Skip to content

Commit f1bee82

Browse files
avargitster
authored andcommitted
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 ad0fb65 (repo-settings: parse core.untrackedCache, 2019-08-13) for when the "unset" and "keep" handling for core.untrackedCache was consolidated, and aaf633c (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>
1 parent c6b4888 commit f1bee82

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

fetch-negotiator.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ void fetch_negotiator_init(struct repository *r,
1919
return;
2020

2121
case FETCH_NEGOTIATION_DEFAULT:
22-
default:
2322
default_negotiator_init(negotiator);
2423
return;
24+
case FETCH_NEGOTIATION_NONE:
25+
case FETCH_NEGOTIATION_UNSET:
26+
BUG("FETCH_NEGOTIATION_{NONE,UNSET} used outside of prepare_repo_settings()!");
2527
}
2628
}

read-cache.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1944,13 +1944,18 @@ static void tweak_untracked_cache(struct index_state *istate)
19441944

19451945
prepare_repo_settings(r);
19461946

1947-
if (r->settings.core_untracked_cache == UNTRACKED_CACHE_REMOVE) {
1947+
switch (r->settings.core_untracked_cache) {
1948+
case UNTRACKED_CACHE_REMOVE:
19481949
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:
19531952
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+
}
19541959
}
19551960

19561961
static void tweak_split_index(struct index_state *istate)

0 commit comments

Comments
 (0)