git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v2 1/3] repo-settings: create core.featureAdoptionRate setting

From
Junio C Hamano <gitster@pobox.com>
Date
Jun 28, 2019, 21:42 UTC
Message-ID
<xmqq8stl8k09.fsf@gitster-ct.c.googlers.com>
In-Reply-To
<bdaee3ea9df0533c268d6bebbd252c00cfbaccd6.1560957119.git.gitgitgadget@gmail.com>
"Derrick Stolee via GitGitGadget" <gitgitgadget@gmail.com> writes:
Show 25 quoted lines
> @@ -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;
>  static int detach_auto = 1;
>  static timestamp_t gc_log_expire_time;
>  static const char *gc_log_expire = "1.day.ago";
> @@ -148,7 +148,6 @@ static void gc_config(void)
>  	git_config_get_int("gc.aggressivedepth", &aggressive_depth);
>  	git_config_get_int("gc.auto", &gc_auto_threshold);
>  	git_config_get_int("gc.autopacklimit", &gc_auto_pack_limit);
> -	git_config_get_bool("gc.writecommitgraph", &gc_write_commit_graph);
>  	git_config_get_bool("gc.autodetach", &detach_auto);
>  	git_config_get_expiry("gc.pruneexpire", &prune_expire);
>  	git_config_get_expiry("gc.worktreepruneexpire", &prune_worktrees_expire);
> @@ -685,7 +684,8 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
>  		clean_pack_garbage();
>  	}
>  
> -	if (gc_write_commit_graph)
> +	prepare_repo_settings(the_repository);
> +	if (the_repository->settings->gc_write_commit_graph == 1)
>  		write_commit_graph_reachable(get_object_directory(), 0,
>  					     !quiet && !daemonized);

OK, so the general idea is to move per-subsystem local variables to new fields in the repository structure, stop parsing the configuration in per-subsystem config callback, which is how the configuration for the writing side is done above, and ...

Show 34 quoted lines
>  
> diff --git a/commit-graph.c b/commit-graph.c
> index 7c5e54875f..b09c465a7a 100644
> --- a/commit-graph.c
> +++ b/commit-graph.c
> @@ -16,6 +16,7 @@
>  #include "hashmap.h"
>  #include "replace-object.h"
>  #include "progress.h"
> +#include "repo-settings.h"
>  
>  #define GRAPH_SIGNATURE 0x43475048 /* "CGPH" */
>  #define GRAPH_CHUNKID_OIDFANOUT 0x4f494446 /* "OIDF" */
> @@ -311,7 +312,6 @@ static void prepare_commit_graph_one(struct repository *r, const char *obj_dir)
>  static int prepare_commit_graph(struct repository *r)
>  {
>  	struct object_directory *odb;
> -	int config_value;
>  
>  	if (git_env_bool(GIT_TEST_COMMIT_GRAPH_DIE_ON_LOAD, 0))
>  		die("dying as requested by the '%s' variable on commit-graph load!",
> @@ -321,9 +321,10 @@ static int prepare_commit_graph(struct repository *r)
>  		return !!r->objects->commit_graph;
>  	r->objects->commit_graph_attempted = 1;
>  
> +	prepare_repo_settings(r);
> +
>  	if (!git_env_bool(GIT_TEST_COMMIT_GRAPH, 0) &&
> -	    (repo_config_get_bool(r, "core.commitgraph", &config_value) ||
> -	    !config_value))
> +	    r->settings->core_commit_graph != 1)
>  		/*
>  		 * This repository is not configured to use commit graphs, so
>  		 * do not load one. (But report commit_graph_attempted anyway

... how the reading side is done here. And then instead let the new repo-settings module read them ...

Show 36 quoted lines
> diff --git a/repo-settings.c b/repo-settings.c
> new file mode 100644
> index 0000000000..f7fc2a1959
> --- /dev/null
> +++ b/repo-settings.c
> @@ -0,0 +1,44 @@
> +#include "cache.h"
> +#include "repository.h"
> +#include "config.h"
> +#include "repo-settings.h"
> +
> +#define UPDATE_DEFAULT(s,v) do { if (s == -1) { s = v; } } while(0)
> +
> +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.featureadoptionrate")) {
> +		int rate = git_config_int(key, value);
> +		if (rate >= 3) {
> +			UPDATE_DEFAULT(rs->core_commit_graph, 1);
> +			UPDATE_DEFAULT(rs->gc_write_commit_graph, 1);
> +		}
> +		return 0;
> +	}
> +	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;
> +	}
> +
> +	return 1;
> +}

... like this. If a concrete/underlying configuration variable appears in the configuration data stream, the fields would get their values overwritten, and if the adoption rate setting appears _before_ concreate ones, they affect the value in the fields. So the assignment to these fields when the adoption rate setting is seen survives only when the underlying variable does not appear anywhere in the configuration dasta stream at all.

Which is exactly what we want.  Nicely written.
Show 26 quoted lines
> +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;
> +
> +	repo_config(r, git_repo_config, r->settings);
> +}
> diff --git a/repo-settings.h b/repo-settings.h
> new file mode 100644
> index 0000000000..11d08648e1
> --- /dev/null
> +++ b/repo-settings.h
> @@ -0,0 +1,13 @@
> +#ifndef REPO_SETTINGS_H
> +#define REPO_SETTINGS_H
> +
> +struct repo_settings {
> +	char core_commit_graph;
> +	char gc_write_commit_graph;
> +};

I do not see a particular reason to favor type "char" here. "char" is wider than e.g. "signed int :2", if you wanted to save space compared to a more obvious and naive type, e.g. "int". More importantly, the language does not guarantee signedness of "char", so the sentinel value of "-1" is a bit tricky to use, as you have to be prepared to see your code used on an "unsigned char" platform.

Use of "signed char" would be OK, but this is a singleton instance per repository, so I am not sure how much it matters to save a few words here by not using the most natural "int" type.

Previous: Derrick StoleeNext: Derrick Stolee
Message 26 of 48 in “[RFC] Create 'core.size=large' setting to update config defaults”
  1. 00/11 [RFC] Create 'core.size=large' setting to update config defaultsDerrick Stolee via GitGitGadget, Jun 3, 2019
  2. 01/11 repo-settings: create repo.size=large settingDerrick Stolee via GitGitGadget, Jun 3, 2019
  3. Jeff HostetlerJun 3, 2019
  4. 02/11 repo-settings: use index.version=4 by defaultDerrick Stolee via GitGitGadget, Jun 3, 2019
  5. 05/11 status: add warning when a/b calculation takes too long for long/normal formatJeff Hostetler via GitGitGadget, Jun 3, 2019
  6. 09/11 fetch: warn about forced updates after branch listDerrick Stolee via GitGitGadget, Jun 3, 2019
  7. 07/11 repo-settings: status.aheadBehind=falseDerrick Stolee via GitGitGadget, Jun 3, 2019
  8. 11/11 repo-settings: fetch.showForcedUpdates=falseDerrick Stolee via GitGitGadget, Jun 3, 2019
  9. 10/11 pull: add --[no-]show-forced-updates passthrough to fetchDerrick Stolee via GitGitGadget, Jun 3, 2019
  10. 08/11 fetch: add --[no-]show-forced-updates argumentDerrick Stolee via GitGitGadget, Jun 3, 2019
  11. 03/11 repo-settings: pack.useSparse=trueDerrick Stolee via GitGitGadget, Jun 3, 2019
  12. 06/11 status: ignore status.aheadbehind in porcelain formatsJeff Hostetler via GitGitGadget, Jun 3, 2019
  13. 04/11 status: add status.aheadbehind settingJeff Hostetler via GitGitGadget, Jun 3, 2019
  14. Derrick StoleeJun 3, 2019
  15. Johannes SchindelinJun 4, 2019
  16. Derrick StoleeJun 4, 2019
  17. Junio C HamanoJun 5, 2019
  18. Derrick StoleeJun 6, 2019
  19. Junio C HamanoJun 6, 2019
  20. 0/3 [RFC] Create 'core.featureAdoptionRate' setting to update config defaultsDerrick Stolee via GitGitGadget, Jun 19, 2019
  21. 2/3 repo-settings: use index.version=4 by defaultDerrick Stolee via GitGitGadget, Jun 19, 2019
  22. 3/3 repo-settings: pack.useSparse=trueDerrick Stolee via GitGitGadget, Jun 19, 2019
  23. 1/3 repo-settings: create core.featureAdoptionRate settingDerrick Stolee via GitGitGadget, Jun 19, 2019
  24. Junio C HamanoJun 28, 2019
  25. Derrick StoleeJun 28, 2019
  26. Junio C HamanoJun 28, 2019
  27. Derrick StoleeJun 29, 2019
  28. Carlo ArenasJun 30, 2019
  29. Derrick StoleeJul 1, 2019
  30. Ævar Arnfjörð BjarmasonJul 2, 2019
  31. Duy NguyenJul 2, 2019
  32. Derrick StoleeJul 2, 2019
  33. Junio C HamanoJul 2, 2019
  34. 0/3 [RFC] Create 'core.featureAdoptionRate' setting to update config defaultsDerrick Stolee via GitGitGadget, Jul 1, 2019
  35. 2/3 repo-settings: use index.version=4 by defaultDerrick Stolee via GitGitGadget, Jul 1, 2019
  36. 1/3 repo-settings: create core.featureAdoptionRate settingDerrick Stolee via GitGitGadget, Jul 1, 2019
  37. Carlo ArenasJul 1, 2019
  38. Duy NguyenJul 2, 2019
  39. Ævar Arnfjörð BjarmasonJul 2, 2019
  40. Jakub NarebskiJul 4, 2019
  41. 3/3 repo-settings: pack.useSparse=trueDerrick Stolee via GitGitGadget, Jul 1, 2019
  42. Derrick StoleeJul 8, 2019
  43. Taylor BlauJul 9, 2019
  44. Junio C HamanoJul 9, 2019
  45. Derrick StoleeJul 9, 2019
  46. Junio C HamanoJul 9, 2019
  47. Derrick StoleeJul 22, 2019
  48. Jakub NarebskiJul 11, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.