]> git.ipfire.org Git - thirdparty/git.git/commitdiff
read-cache & fetch-negotiator: check "enum" values in switch()
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>
Tue, 21 Sep 2021 13:13:01 +0000 (15:13 +0200)
committerJunio C Hamano <gitster@pobox.com>
Wed, 22 Sep 2021 20:15:00 +0000 (13:15 -0700)
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>
fetch-negotiator.c
read-cache.c

index 57ed5784e1468aa661d59446273ba9cbbad760ca..e61e40cb2990ec5a0e4d472565f09e980bbb7f7f 100644 (file)
@@ -19,8 +19,10 @@ void fetch_negotiator_init(struct repository *r,
                return;
 
        case FETCH_NEGOTIATION_DEFAULT:
-       default:
                default_negotiator_init(negotiator);
                return;
+       case FETCH_NEGOTIATION_NONE:
+       case FETCH_NEGOTIATION_UNSET:
+               BUG("FETCH_NEGOTIATION_{NONE,UNSET} used outside of prepare_repo_settings()!");
        }
 }
index 9048ef9e905251bacb516be6afdb474b4e59648f..489281383396053b280ad093a626e91e15cd56f6 100644 (file)
@@ -1944,13 +1944,18 @@ static void tweak_untracked_cache(struct index_state *istate)
 
        prepare_repo_settings(r);
 
-       if (r->settings.core_untracked_cache  == UNTRACKED_CACHE_REMOVE) {
+       switch (r->settings.core_untracked_cache) {
+       case UNTRACKED_CACHE_REMOVE:
                remove_untracked_cache(istate);
-               return;
-       }
-
-       if (r->settings.core_untracked_cache == UNTRACKED_CACHE_WRITE)
+               break;
+       case UNTRACKED_CACHE_WRITE:
                add_untracked_cache(istate);
+               break;
+       case UNTRACKED_CACHE_KEEP:
+               break;
+       case UNTRACKED_CACHE_UNSET:
+               BUG("UNTRACKED_CACHE_UNSET used outside of prepare_repo_settings()!");
+       }
 }
 
 static void tweak_split_index(struct index_state *istate)