Skip to content

Commit 72aeb18

Browse files
aspiersgitster
authored andcommitted
clean.c, ls-files.c: respect encapsulation of exclude_list_groups
Consumers of the dir.c traversal API should avoid assuming knowledge of the internal implementation of exclude_list_groups. Therefore when adding items to an exclude list, it should be accessed via the pointer returned from add_exclude_list(), rather than by referencing a location within dir.exclude_list_groups[EXC_CMDL]. Signed-off-by: Adam Spiers <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6f53fea commit 72aeb18

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

builtin/clean.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
4545
static const char **pathspec;
4646
struct strbuf buf = STRBUF_INIT;
4747
struct string_list exclude_list = STRING_LIST_INIT_NODUP;
48+
struct exclude_list *el;
4849
const char *qname;
4950
char *seen = NULL;
5051
struct option options[] = {
@@ -97,10 +98,9 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
9798
if (!ignored)
9899
setup_standard_excludes(&dir);
99100

100-
add_exclude_list(&dir, EXC_CMDL, "--exclude option");
101+
el = add_exclude_list(&dir, EXC_CMDL, "--exclude option");
101102
for (i = 0; i < exclude_list.nr; i++)
102-
add_exclude(exclude_list.items[i].string, "", 0,
103-
&dir.exclude_list_group[EXC_CMDL].el[0], -(i+1));
103+
add_exclude(exclude_list.items[i].string, "", 0, el, -(i+1));
104104

105105
pathspec = get_pathspec(prefix, argv);
106106

builtin/ls-files.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -421,10 +421,10 @@ static int option_parse_z(const struct option *opt,
421421
static int option_parse_exclude(const struct option *opt,
422422
const char *arg, int unset)
423423
{
424-
struct exclude_list_group *group = opt->value;
424+
struct string_list *exclude_list = opt->value;
425425

426426
exc_given = 1;
427-
add_exclude(arg, "", 0, &group->el[0], --exclude_args);
427+
string_list_append(exclude_list, arg);
428428

429429
return 0;
430430
}
@@ -453,9 +453,11 @@ static int option_parse_exclude_standard(const struct option *opt,
453453

454454
int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)
455455
{
456-
int require_work_tree = 0, show_tag = 0;
456+
int require_work_tree = 0, show_tag = 0, i;
457457
const char *max_prefix;
458458
struct dir_struct dir;
459+
struct exclude_list *el;
460+
struct string_list exclude_list = STRING_LIST_INIT_NODUP;
459461
struct option builtin_ls_files_options[] = {
460462
{ OPTION_CALLBACK, 'z', NULL, NULL, NULL,
461463
"paths are separated with NUL character",
@@ -490,7 +492,7 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)
490492
OPT_BOOLEAN(0, "resolve-undo", &show_resolve_undo,
491493
"show resolve-undo information"),
492494
{ OPTION_CALLBACK, 'x', "exclude",
493-
&dir.exclude_list_group[EXC_CMDL], "pattern",
495+
&exclude_list, "pattern",
494496
"skip files matching pattern",
495497
0, option_parse_exclude },
496498
{ OPTION_CALLBACK, 'X', "exclude-from", &dir, "file",
@@ -525,9 +527,12 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)
525527
if (read_cache() < 0)
526528
die("index file corrupt");
527529

528-
add_exclude_list(&dir, EXC_CMDL, "--exclude option");
529530
argc = parse_options(argc, argv, prefix, builtin_ls_files_options,
530531
ls_files_usage, 0);
532+
el = add_exclude_list(&dir, EXC_CMDL, "--exclude option");
533+
for (i = 0; i < exclude_list.nr; i++) {
534+
add_exclude(exclude_list.items[i].string, "", 0, el, --exclude_args);
535+
}
531536
if (show_tag || show_valid_bit) {
532537
tag_cached = "H ";
533538
tag_unmerged = "M ";

0 commit comments

Comments
 (0)