Re: [PATCH 1/5] repo-settings: consolidate some config settings
- From
Johannes Schindelin <johannes.schindelin@gmx.de>
- Date
- Jul 23, 2019, 13:12 UTC
- Message-ID
- <nycvar.QRO.7.76.6.1907231512130.21907@tvgsbejvaqbjf.bet>
- In-Reply-To
- <72f652b89c71526cc423e7812de66f41a079f181.1563818059.git.gitgitgadget@gmail.com>
Hi Stolee,
On Mon, 22 Jul 2019, Derrick Stolee via GitGitGadget wrote:
Show 17 quoted lines
> diff --git a/builtin/gc.c b/builtin/gc.c > index c18efadda5..243be2907b 100644 > --- a/builtin/gc.c > +++ b/builtin/gc.c > @@ -27,6 +27,7 @@ > #include "pack-objects.h" > #include "blob.h" > #include "tree.h" > +#include "repo-settings.h" > > #define FAILED_RUN "failed to run %s" > > @@ -41,7 +42,6 @@ static int aggressive_depth = 50; > static int aggressive_window = 250; > static int gc_auto_threshold = 6700; > static int gc_auto_pack_limit = 50; > -static int gc_write_commit_graph;
I _really_ like that direction. Anything that removes global state will improve Git's source code.
Show 12 quoted lines
> [...]
> diff --git a/read-cache.c b/read-cache.c
> index c701f7f8b8..ee1aaa8917 100644
> --- a/read-cache.c
> +++ b/read-cache.c
> [...]
> @@ -2765,7 +2767,7 @@ static int do_write_index(struct index_state *istate, struct tempfile *tempfile,
> }
>
> if (!istate->version) {
> - istate->version = get_index_format_default();
> + istate->version = get_index_format_default(the_repository);It is too bad that `read-cache.h` is not `the_repository`-free at the moment...
Show 34 quoted lines
> if (git_env_bool("GIT_TEST_SPLIT_INDEX", 0))
> init_split_index(istate);
> }
> diff --git a/repo-settings.c b/repo-settings.c
> new file mode 100644
> index 0000000000..13a9128f62
> --- /dev/null
> +++ b/repo-settings.c
> @@ -0,0 +1,44 @@
> +#include "cache.h"
> +#include "repository.h"
> +#include "config.h"
> +#include "repo-settings.h"
> +
> +static int git_repo_config(const char *key, const char *value, void *cb)
> +{
> + struct repo_settings *rs = (struct repo_settings *)cb;
> +
> + if (!strcmp(key, "core.commitgraph")) {
> + rs->core_commit_graph = git_config_bool(key, value);
> + return 0;
> + }
> + if (!strcmp(key, "gc.writecommitgraph")) {
> + rs->gc_write_commit_graph = git_config_bool(key, value);
> + return 0;
> + }
> + if (!strcmp(key, "pack.usesparse")) {
> + rs->pack_use_sparse = git_config_bool(key, value);
> + return 0;
> + }
> + if (!strcmp(key, "index.version")) {
> + rs->index_version = git_config_int(key, value);
> + return 0;
> + }I would actually prefer to use the `repo_config_get_*()` family here. That way, we really avoid re-parsing the config.
Show 38 quoted lines
> +
> + return 1;
> +}
> +
> +void prepare_repo_settings(struct repository *r)
> +{
> + if (r->settings)
> + return;
> +
> + r->settings = xmalloc(sizeof(*r->settings));
> +
> + /* Defaults */
> + r->settings->core_commit_graph = -1;
> + r->settings->gc_write_commit_graph = -1;
> + r->settings->pack_use_sparse = -1;
> + r->settings->index_version = -1;
> +
> + repo_config(r, git_repo_config, r->settings);
> +}
> diff --git a/repo-settings.h b/repo-settings.h
> new file mode 100644
> index 0000000000..1151c2193a
> --- /dev/null
> +++ b/repo-settings.h
> @@ -0,0 +1,15 @@
> +#ifndef REPO_SETTINGS_H
> +#define REPO_SETTINGS_H
> +
> +struct repo_settings {
> + int core_commit_graph;
> + int gc_write_commit_graph;
> + int pack_use_sparse;
> + int index_version;
> +};
> +
> +struct repository;
> +
> +void prepare_repo_settings(struct repository *r);Hmm. I can see that you wanted to encapsulate this, but I do not really agree that this needs to be encapsulated away from `repository.h`. I'd rather declare `struct repo_settings` in `repository.h` and then make the `settings` a field of that type (as opposed to a pointer to that type). In general, I like to avoid unnecessary `malloc()`s, and this here instance is one of them.
Thanks, Dscho
Show 27 quoted lines
> +
> +#endif /* REPO_SETTINGS_H */
> diff --git a/repository.h b/repository.h
> index 4fb6a5885f..352afc9cd8 100644
> --- a/repository.h
> +++ b/repository.h
> @@ -4,6 +4,7 @@
> #include "path.h"
>
> struct config_set;
> +struct repo_settings;
> struct git_hash_algo;
> struct index_state;
> struct lock_file;
> @@ -72,6 +73,8 @@ struct repository {
> */
> char *submodule_prefix;
>
> + struct repo_settings *settings;
> +
> /* Subsystems */
> /*
> * Repository's config which contains key-value pairs from the usual
> --
> gitgitgadget
>
>