read-cache & fetch-negotiator: check "enum" values in switch()

Change tweak_untracked_cache() in "read-cache.c" to use a switch() to have the compiler assert that we checked all possible values in the "enum untracked_cache_setting" type, and likewise remove the "default" case in fetch_negotiator_init() in favor of checking for "FETCH_NEGOTIATION_UNSET" and "FETCH_NEGOTIATION_NONE". As will be discussed in a subsequent we'll only ever have either of these set to FETCH_NEGOTIATION_NONE, FETCH_NEGOTIATION_UNSET and UNTRACKED_CACHE_UNSET within the prepare_repo_settings() function itself. In preparation for fixing that code let's add a BUG() here to mark this as unreachable code. See ad0fb659993 (repo-settings: parse core.untrackedCache, 2019-08-13) for when the "unset" and "keep" handling for core.untrackedCache was consolidated, and aaf633c2ad1 (repo-settings: create feature.experimental setting, 2019-08-13) for the addition of the "default" pattern in "fetch-negotiator.c". Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ævar Arnfjörð Bjarmason committed Sep 21, 2021 at 15:13 UTC f1bee828734c052eeabb6b652a98c0498efdff6b
2 files changed +13 -6
fetch-negotiator.c
+3 -1
@@ -19,8 +19,10 @@ void fetch_negotiator_init(struct repository *r,
19 return;
20
21 case FETCH_NEGOTIATION_DEFAULT:
22 - default:
22 default_negotiator_init(negotiator);
23 return;
24 + case FETCH_NEGOTIATION_NONE:
25 + case FETCH_NEGOTIATION_UNSET:
26 + BUG("FETCH_NEGOTIATION_{NONE,UNSET} used outside of prepare_repo_settings()!");
27 }
28 }
read-cache.c
+10 -5
@@ -1944,13 +1944,18 @@ static void tweak_untracked_cache(struct index_state *istate)
1944
1945 prepare_repo_settings(r);
1946
1947 - if (r->settings.core_untracked_cache == UNTRACKED_CACHE_REMOVE) {
1947 + switch (r->settings.core_untracked_cache) {
1948 + case UNTRACKED_CACHE_REMOVE:
1949 remove_untracked_cache(istate);
1949 - return;
1950 - }
1951 -
1952 - if (r->settings.core_untracked_cache == UNTRACKED_CACHE_WRITE)
1950 + break;
1951 + case UNTRACKED_CACHE_WRITE:
1952 add_untracked_cache(istate);
1953 + break;
1954 + case UNTRACKED_CACHE_KEEP:
1955 + break;
1956 + case UNTRACKED_CACHE_UNSET:
1957 + BUG("UNTRACKED_CACHE_UNSET used outside of prepare_repo_settings()!");
1958 + }
1959 }
1960
1961 static void tweak_split_index(struct index_state *istate)