mirror of
https://github.com/git/git
synced 2024-08-25 02:35:46 +00:00
![Ævar Arnfjörð Bjarmason](/assets/img/avatar_default.png)
Simplify the setup code in repo-settings.c in various ways, making the code shorter, easier to read, and requiring fewer hacks to do the same thing as it did before: Since7211b9e753
(repo-settings: consolidate some config settings, 2019-08-13) we have memset() the whole "settings" structure to -1 in prepare_repo_settings(), and subsequently relied on the -1 value. Most of the fields did not need to be initialized to -1, and because we were doing that we had the enum labels "UNTRACKED_CACHE_UNSET" and "FETCH_NEGOTIATION_UNSET" purely to reflect the resulting state created this memset() in prepare_repo_settings(). No other code used or relied on them, more on that below. For the rest most of the subsequent "are we -1, then read xyz" can simply be removed by re-arranging what we read first. E.g. when setting the "index.version" setting we should have first read "feature.experimental", so that it (and "feature.manyfiles") can provide a default for our "index.version". Instead the code setting it, added when "feature.manyFiles"[1] was created, was using the UPDATE_DEFAULT_BOOL() macro added in an earlier commit[2]. That macro is now gone, since it was only needed for this pattern of reading things in the wrong order. This also fixes an (admittedly obscure) logic error where we'd conflate an explicit "-1" value in the config with our own earlier memset() -1. We can also remove the UPDATE_DEFAULT_BOOL() wrapper added in [3]. Using it is redundant to simply using the return value from repo_config_get_bool(), which is non-zero if the provided key exists in the config. Details on edge cases relating to the memset() to -1, continued from "more on that below" above: * UNTRACKED_CACHE_KEEP: In [4] the "unset" and "keep" handling for core.untrackedCache was consolidated. But it while we understand the "keep" value, we don't handle it differently than the case of any other unknown value. So let's retain UNTRACKED_CACHE_KEEP and remove the UNTRACKED_CACHE_UNSET setting (which was always implicitly UNTRACKED_CACHE_KEEP before). We don't need to inform any code after prepare_repo_settings() that the setting was "unset", as far as anyone else is concerned it's core.untrackedCache=keep. if "core.untrackedcache" isn't present in the config. * FETCH_NEGOTIATION_UNSET & FETCH_NEGOTIATION_NONE: Since these two two enum fields added in [5] don't rely on the memzero() setting them to "-1" anymore we don't have to provide them with explicit values. 1.c6cc4c5afd
(repo-settings: create feature.manyFiles setting, 2019-08-13) 2.31b1de6a09
(commit-graph: turn on commit-graph by default, 2019-08-13) 3.31b1de6a09
(commit-graph: turn on commit-graph by default, 2019-08-13) 4.ad0fb65999
(repo-settings: parse core.untrackedCache, 2019-08-13) 5.aaf633c2ad
(repo-settings: create feature.experimental setting, 2019-08-13) Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
26 lines
599 B
C
26 lines
599 B
C
#include "git-compat-util.h"
|
|
#include "fetch-negotiator.h"
|
|
#include "negotiator/default.h"
|
|
#include "negotiator/skipping.h"
|
|
#include "negotiator/noop.h"
|
|
#include "repository.h"
|
|
|
|
void fetch_negotiator_init(struct repository *r,
|
|
struct fetch_negotiator *negotiator)
|
|
{
|
|
prepare_repo_settings(r);
|
|
switch(r->settings.fetch_negotiation_algorithm) {
|
|
case FETCH_NEGOTIATION_SKIPPING:
|
|
skipping_negotiator_init(negotiator);
|
|
return;
|
|
|
|
case FETCH_NEGOTIATION_NOOP:
|
|
noop_negotiator_init(negotiator);
|
|
return;
|
|
|
|
case FETCH_NEGOTIATION_DEFAULT:
|
|
default_negotiator_init(negotiator);
|
|
return;
|
|
}
|
|
}
|