Message ID | patch-v2-3.5-9f1bb0496ed-20210916T182918Z-avarab@gmail.com (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | repo-settings.c: refactor for clarity, get rid of hacks etc. | expand |
Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes: > 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". > > 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". Covering all possibility is good, but ... > > Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> > --- > fetch-negotiator.c | 3 ++- > read-cache.c | 15 ++++++++++----- > 2 files changed, 12 insertions(+), 6 deletions(-) > > diff --git a/fetch-negotiator.c b/fetch-negotiator.c > index 57ed5784e14..e7b5878be7c 100644 > --- a/fetch-negotiator.c > +++ b/fetch-negotiator.c > @@ -19,7 +19,8 @@ void fetch_negotiator_init(struct repository *r, > return; > > case FETCH_NEGOTIATION_DEFAULT: > - default: > + case FETCH_NEGOTIATION_UNSET: > + case FETCH_NEGOTIATION_NONE: > default_negotiator_init(negotiator); > return; > } > diff --git a/read-cache.c b/read-cache.c > index 9048ef9e905..9dd84d69f00 100644 > --- a/read-cache.c > +++ b/read-cache.c > @@ -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_UNSET: > + case UNTRACKED_CACHE_KEEP: > + break; > + } ... this change makes me wonder if default: BUG(...); might have been more appropriate? Are we sure these the flow will reach here with these two values? > + return; > } I do not see why we want to add a no-op return that wasn't there in the original. Perhaps later, but definitely not as a part of this change. > > static void tweak_split_index(struct index_state *istate)
diff --git a/fetch-negotiator.c b/fetch-negotiator.c index 57ed5784e14..e7b5878be7c 100644 --- a/fetch-negotiator.c +++ b/fetch-negotiator.c @@ -19,7 +19,8 @@ void fetch_negotiator_init(struct repository *r, return; case FETCH_NEGOTIATION_DEFAULT: - default: + case FETCH_NEGOTIATION_UNSET: + case FETCH_NEGOTIATION_NONE: default_negotiator_init(negotiator); return; } diff --git a/read-cache.c b/read-cache.c index 9048ef9e905..9dd84d69f00 100644 --- a/read-cache.c +++ b/read-cache.c @@ -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_UNSET: + case UNTRACKED_CACHE_KEEP: + break; + } + return; } static void tweak_split_index(struct index_state *istate)
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". 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> --- fetch-negotiator.c | 3 ++- read-cache.c | 15 ++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-)