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 <git@adamspiers.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Adam Spiers committed
Jan 16, 2013 at 13:25 UTC
72aeb18772deeb386da7dd8997b969877bd29e41
2 files changed
+13
-8
builtin/clean.c
+3
-3
@@ -45,6 +45,7 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
45
static const char **pathspec;
46
struct strbuf buf = STRBUF_INIT;
47
struct string_list exclude_list = STRING_LIST_INIT_NODUP;
48
+ struct exclude_list *el;
49
const char *qname;
50
char *seen = NULL;
51
struct option options[] = {
@@ -97,10 +98,9 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
98
if (!ignored)
99
setup_standard_excludes(&dir);
100
100
- add_exclude_list(&dir, EXC_CMDL, "--exclude option");
101
+ el = add_exclude_list(&dir, EXC_CMDL, "--exclude option");
102
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));
104
105
pathspec = get_pathspec(prefix, argv);
106
builtin/ls-files.c
+10
-5
@@ -421,10 +421,10 @@ static int option_parse_z(const struct option *opt,
421
static int option_parse_exclude(const struct option *opt,
422
const char *arg, int unset)
423
{
424
- struct exclude_list_group *group = opt->value;
424
+ struct string_list *exclude_list = opt->value;
425
426
exc_given = 1;
427
- add_exclude(arg, "", 0, &group->el[0], --exclude_args);
427
+ string_list_append(exclude_list, arg);
428
429
return 0;
430
}
@@ -453,9 +453,11 @@ static int option_parse_exclude_standard(const struct option *opt,
453
454
int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)
455
{
456
- int require_work_tree = 0, show_tag = 0;
456
+ int require_work_tree = 0, show_tag = 0, i;
457
const char *max_prefix;
458
struct dir_struct dir;
459
+ struct exclude_list *el;
460
+ struct string_list exclude_list = STRING_LIST_INIT_NODUP;
461
struct option builtin_ls_files_options[] = {
462
{ OPTION_CALLBACK, 'z', NULL, NULL, NULL,
463
"paths are separated with NUL character",
@@ -490,7 +492,7 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)
492
OPT_BOOLEAN(0, "resolve-undo", &show_resolve_undo,
493
"show resolve-undo information"),
494
{ OPTION_CALLBACK, 'x', "exclude",
493
- &dir.exclude_list_group[EXC_CMDL], "pattern",
495
+ &exclude_list, "pattern",
496
"skip files matching pattern",
497
0, option_parse_exclude },
498
{ OPTION_CALLBACK, 'X', "exclude-from", &dir, "file",
@@ -525,9 +527,12 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)
527
if (read_cache() < 0)
528
die("index file corrupt");
529
528
- add_exclude_list(&dir, EXC_CMDL, "--exclude option");
530
argc = parse_options(argc, argv, prefix, builtin_ls_files_options,
531
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
+ }
536
if (show_tag || show_valid_bit) {
537
tag_cached = "H ";
538
tag_unmerged = "M ";