clean.c, ls-files.c: respect encapsulation of exclude_list_groups
authorAdam Spiers <git@adamspiers.org>
Wed, 16 Jan 2013 13:25:58 +0000 (13:25 +0000)
committerJunio C Hamano <gitster@pobox.com>
Wed, 16 Jan 2013 17:43:35 +0000 (09:43 -0800)
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>
builtin/clean.c
builtin/ls-files.c
index b098288ad151b5dc2dfdcb27f463215ca440f4e6..b9cb7ad4e088257fd0900816f883a92b7a3a5b43 100644 (file)
@@ -45,6 +45,7 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
        static const char **pathspec;
        struct strbuf buf = STRBUF_INIT;
        struct string_list exclude_list = STRING_LIST_INIT_NODUP;
+       struct exclude_list *el;
        const char *qname;
        char *seen = NULL;
        struct option options[] = {
@@ -97,10 +98,9 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
        if (!ignored)
                setup_standard_excludes(&dir);
 
-       add_exclude_list(&dir, EXC_CMDL, "--exclude option");
+       el = add_exclude_list(&dir, EXC_CMDL, "--exclude option");
        for (i = 0; i < exclude_list.nr; i++)
-               add_exclude(exclude_list.items[i].string, "", 0,
-                           &dir.exclude_list_group[EXC_CMDL].el[0], -(i+1));
+               add_exclude(exclude_list.items[i].string, "", 0, el, -(i+1));
 
        pathspec = get_pathspec(prefix, argv);
 
index fa9ccb80dc39b8c52406fdea5056c23ad41576d9..b4d8b017a835c0f2911306c0f1c445d4584e913d 100644 (file)
@@ -421,10 +421,10 @@ static int option_parse_z(const struct option *opt,
 static int option_parse_exclude(const struct option *opt,
                                const char *arg, int unset)
 {
-       struct exclude_list_group *group = opt->value;
+       struct string_list *exclude_list = opt->value;
 
        exc_given = 1;
-       add_exclude(arg, "", 0, &group->el[0], --exclude_args);
+       string_list_append(exclude_list, arg);
 
        return 0;
 }
@@ -453,9 +453,11 @@ static int option_parse_exclude_standard(const struct option *opt,
 
 int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)
 {
-       int require_work_tree = 0, show_tag = 0;
+       int require_work_tree = 0, show_tag = 0, i;
        const char *max_prefix;
        struct dir_struct dir;
+       struct exclude_list *el;
+       struct string_list exclude_list = STRING_LIST_INIT_NODUP;
        struct option builtin_ls_files_options[] = {
                { OPTION_CALLBACK, 'z', NULL, NULL, NULL,
                        "paths are separated with NUL character",
@@ -490,7 +492,7 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)
                OPT_BOOLEAN(0, "resolve-undo", &show_resolve_undo,
                            "show resolve-undo information"),
                { OPTION_CALLBACK, 'x', "exclude",
-                       &dir.exclude_list_group[EXC_CMDL], "pattern",
+                       &exclude_list, "pattern",
                        "skip files matching pattern",
                        0, option_parse_exclude },
                { OPTION_CALLBACK, 'X', "exclude-from", &dir, "file",
@@ -525,9 +527,12 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)
        if (read_cache() < 0)
                die("index file corrupt");
 
-       add_exclude_list(&dir, EXC_CMDL, "--exclude option");
        argc = parse_options(argc, argv, prefix, builtin_ls_files_options,
                        ls_files_usage, 0);
+       el = add_exclude_list(&dir, EXC_CMDL, "--exclude option");
+       for (i = 0; i < exclude_list.nr; i++) {
+               add_exclude(exclude_list.items[i].string, "", 0, el, --exclude_args);
+       }
        if (show_tag || show_valid_bit) {
                tag_cached = "H ";
                tag_unmerged = "M ";