@matheusbsbs / matheus-bagliano / commits / f7f5c6c0ba
Fork 0

clean: consolidate handling of ignored parameters

I spent a long time trying to figure out how and whether the code worked with different values of ignore, ignore_only, and remove_directories. After lots of time setting up lots of testcases, sifting through lots of print statements, and walking through the debugger, I finally realized that one piece of code related to how it was all setup was found in clean.c rather than dir.c. Make a change that would have made it easier for me to do the extra testing by putting this handling in one spot. Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Elijah Newren committed Jun 11, 2020 at 06:59 UTC f7f5c6c0baf6b6219b38e69d8623b95cc3cdd3d3
1 file changed +7 -9
builtin/clean.c
+7 -9
@@ -924,12 +924,6 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
924 0);
925
926 memset(&dir, 0, sizeof(dir));
927 - if (ignored_only)
928 - dir.flags |= DIR_SHOW_IGNORED;
929 -
930 - if (ignored && ignored_only)
931 - die(_("-x and -X cannot be used together"));
932 -
927 if (!interactive && !dry_run && !force) {
928 if (config_set)
929 die(_("clean.requireForce set to true and neither -i, -n, nor -f given; "
@@ -946,6 +940,13 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
940
941 dir.flags |= DIR_SHOW_OTHER_DIRECTORIES;
942
943 + if (ignored && ignored_only)
944 + die(_("-x and -X cannot be used together"));
945 + if (!ignored)
946 + setup_standard_excludes(&dir);
947 + if (ignored_only)
948 + dir.flags |= DIR_SHOW_IGNORED;
949 +
950 if (argc) {
951 /*
952 * Remaining args implies pathspecs specified, and we should
@@ -960,9 +961,6 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
961 if (read_cache() < 0)
962 die(_("index file corrupt"));
963
963 - if (!ignored)
964 - setup_standard_excludes(&dir);
965 -
964 pl = add_pattern_list(&dir, EXC_CMDL, "--exclude option");
965 for (i = 0; i < exclude_list.nr; i++)
966 add_pattern(exclude_list.items[i].string, "", 0, pl, -(i+1));