git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "Derrick Stolee via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Johannes.Schindelin@gmx.de, peff@peff.net, jnareb@gmail.com,
	pclouds@gmail.com, carenas@gmail.com, avarab@gmail.com,
	Junio C Hamano <gitster@pobox.com>,
	Derrick Stolee <dstolee@microsoft.com>
Subject: [PATCH v2 3/5] repo-settings: parse core.untrackedCache
Date: Wed, 24 Jul 2019 19:23:16 -0700 (PDT)	[thread overview]
Message-ID: <49be7a73454b13b04270531eece87a2c6f6d3189.1564021393.git.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.292.v2.git.gitgitgadget@gmail.com>

From: Derrick Stolee <dstolee@microsoft.com>

The core.untrackedCache config setting is slightly complicated,
so clarify its use and centralize its parsing into the repo
settings.

The default value is "keep" (returned as -1), which persists the
untracked cache if it exists.

If the value is set as "false" (returned as 0), then remove the
untracked cache if it exists.

If the value is set as "true" (returned as 1), then write the
untracked cache and persist it.

Instead of relying on magic values of -1, 0, and 1, split these
options into an enum. This allows the use of "-1" as a
default value. After parsing the config options, if the value is
unset we can initialize it to UNTRACKED_CACHE_KEEP.

Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
---
 builtin/update-index.c |  7 +++++--
 config.c               | 24 ------------------------
 read-cache.c           | 19 +++++++++----------
 repo-settings.c        | 21 ++++++++++++++++++++-
 repo-settings.h        |  8 ++++++++
 5 files changed, 42 insertions(+), 37 deletions(-)

diff --git a/builtin/update-index.c b/builtin/update-index.c
index dff2f4b837..5ced51c1ee 100644
--- a/builtin/update-index.c
+++ b/builtin/update-index.c
@@ -18,6 +18,7 @@
 #include "dir.h"
 #include "split-index.h"
 #include "fsmonitor.h"
+#include "repo-settings.h"
 
 /*
  * Default to not allowing changes to the list of files. The
@@ -966,6 +967,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
 	struct parse_opt_ctx_t ctx;
 	strbuf_getline_fn getline_fn;
 	int parseopt_state = PARSE_OPT_UNKNOWN;
+	struct repository *r = the_repository;
 	struct option options[] = {
 		OPT_BIT('q', NULL, &refresh_args.flags,
 			N_("continue refresh even when index needs update"),
@@ -1180,11 +1182,12 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
 		remove_split_index(&the_index);
 	}
 
+	prepare_repo_settings(r);
 	switch (untracked_cache) {
 	case UC_UNSPECIFIED:
 		break;
 	case UC_DISABLE:
-		if (git_config_get_untracked_cache() == 1)
+		if (r->settings.core_untracked_cache == UNTRACKED_CACHE_WRITE)
 			warning(_("core.untrackedCache is set to true; "
 				  "remove or change it, if you really want to "
 				  "disable the untracked cache"));
@@ -1196,7 +1199,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
 		return !test_if_untracked_cache_is_supported();
 	case UC_ENABLE:
 	case UC_FORCE:
-		if (git_config_get_untracked_cache() == 0)
+		if (r->settings.core_untracked_cache == UNTRACKED_CACHE_REMOVE)
 			warning(_("core.untrackedCache is set to false; "
 				  "remove or change it, if you really want to "
 				  "enable the untracked cache"));
diff --git a/config.c b/config.c
index faa57e436c..3241dbc54d 100644
--- a/config.c
+++ b/config.c
@@ -2277,30 +2277,6 @@ int git_config_get_expiry_in_days(const char *key, timestamp_t *expiry, timestam
 	return -1; /* thing exists but cannot be parsed */
 }
 
-int git_config_get_untracked_cache(void)
-{
-	int val = -1;
-	const char *v;
-
-	/* Hack for test programs like test-dump-untracked-cache */
-	if (ignore_untracked_cache_config)
-		return -1;
-
-	if (!git_config_get_maybe_bool("core.untrackedcache", &val))
-		return val;
-
-	if (!git_config_get_value("core.untrackedcache", &v)) {
-		if (!strcasecmp(v, "keep"))
-			return -1;
-
-		error(_("unknown core.untrackedCache value '%s'; "
-			"using 'keep' default value"), v);
-		return -1;
-	}
-
-	return -1; /* default value */
-}
-
 int git_config_get_split_index(void)
 {
 	int val;
diff --git a/read-cache.c b/read-cache.c
index bda665a25a..3761b9a171 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -1846,18 +1846,17 @@ static void check_ce_order(struct index_state *istate)
 
 static void tweak_untracked_cache(struct index_state *istate)
 {
-	switch (git_config_get_untracked_cache()) {
-	case -1: /* keep: do nothing */
-		break;
-	case 0: /* false */
+	struct repository *r = the_repository;
+
+	prepare_repo_settings(r);
+
+	if (r->settings.core_untracked_cache  == UNTRACKED_CACHE_REMOVE) {
 		remove_untracked_cache(istate);
-		break;
-	case 1: /* true */
-		add_untracked_cache(istate);
-		break;
-	default: /* unknown value: do nothing */
-		break;
+		return;
 	}
+
+	if (r->settings.core_untracked_cache == UNTRACKED_CACHE_WRITE)
+		add_untracked_cache(istate);
 }
 
 static void tweak_split_index(struct index_state *istate)
diff --git a/repo-settings.c b/repo-settings.c
index 3face7d8b9..65b980403c 100644
--- a/repo-settings.c
+++ b/repo-settings.c
@@ -8,6 +8,7 @@
 void prepare_repo_settings(struct repository *r)
 {
 	int value;
+	char *strval;
 
 	if (r->settings_initialized)
 		return;
@@ -22,14 +23,32 @@ void prepare_repo_settings(struct repository *r)
 
 	if (!repo_config_get_bool(r, "index.version", &value))
 		r->settings.index_version = value;
+	if (!repo_config_get_maybe_bool(r, "core.untrackedcache", &value)) {
+		if (value == 0)
+			r->settings.core_untracked_cache = UNTRACKED_CACHE_REMOVE;
+		else
+			r->settings.core_untracked_cache = UNTRACKED_CACHE_WRITE;
+	} else if (!repo_config_get_string(r, "core.untrackedcache", &strval)) {
+		if (!strcasecmp(strval, "keep"))
+			r->settings.core_untracked_cache = UNTRACKED_CACHE_KEEP;
+
+		free(strval);
+	}
+
 
 	if (!repo_config_get_bool(r, "pack.usesparse", &value))
 		r->settings.pack_use_sparse = value;
-
+	
 	if (!repo_config_get_bool(r, "feature.manycommits", &value) && value) {
 		UPDATE_DEFAULT(r->settings.core_commit_graph, 1);
 		UPDATE_DEFAULT(r->settings.gc_write_commit_graph, 1);
 	}
 
+	/* Hack for test programs like test-dump-untracked-cache */
+	if (ignore_untracked_cache_config)
+		r->settings.core_untracked_cache = UNTRACKED_CACHE_KEEP;
+	else
+		UPDATE_DEFAULT(r->settings.core_untracked_cache, UNTRACKED_CACHE_KEEP);
+
 	r->settings_initialized = 1;
 }
diff --git a/repo-settings.h b/repo-settings.h
index 89fb0159bf..e9b028e1a9 100644
--- a/repo-settings.h
+++ b/repo-settings.h
@@ -1,11 +1,19 @@
 #ifndef REPO_SETTINGS_H
 #define REPO_SETTINGS_H
 
+enum untracked_cache_setting {
+	UNTRACKED_CACHE_UNSET = -1,
+	UNTRACKED_CACHE_REMOVE = 0,
+	UNTRACKED_CACHE_KEEP = 1,
+	UNTRACKED_CACHE_WRITE = 2
+};
+
 struct repo_settings {
 	int core_commit_graph;
 	int gc_write_commit_graph;
 
 	int index_version;
+	enum untracked_cache_setting core_untracked_cache;
 
 	int pack_use_sparse;
 };
-- 
gitgitgadget


  parent reply	other threads:[~2019-07-25  2:23 UTC|newest]

Thread overview: 61+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-22 17:54 [PATCH 0/5] Create 'feature.*' config area and some centralized config parsing Derrick Stolee via GitGitGadget
2019-07-22 17:54 ` [PATCH 1/5] repo-settings: consolidate some config settings Derrick Stolee via GitGitGadget
2019-07-23 13:12   ` Johannes Schindelin
2019-07-22 17:54 ` [PATCH 2/5] repo-settings: add feature.manyCommits setting Derrick Stolee via GitGitGadget
2019-07-23 14:53   ` Johannes Schindelin
2019-07-24 10:41     ` Derrick Stolee
2019-07-22 17:54 ` [PATCH 4/5] repo-settings: create feature.manyFiles setting Derrick Stolee via GitGitGadget
2019-07-22 17:54 ` [PATCH 3/5] repo-settings: parse core.untrackedCache Derrick Stolee via GitGitGadget
2019-07-23 15:04   ` Johannes Schindelin
2019-07-24 19:27     ` Derrick Stolee
2019-07-22 17:54 ` [PATCH 5/5] repo-settings: create feature.experimental setting Derrick Stolee via GitGitGadget
2019-07-23 15:20   ` Johannes Schindelin
2019-07-25  1:47     ` Derrick Stolee
2019-07-25  2:23 ` [PATCH v2 0/5] Create 'feature.*' config area and some centralized config parsing Derrick Stolee via GitGitGadget
2019-07-25  2:23   ` [PATCH v2 1/5] repo-settings: consolidate some config settings Derrick Stolee via GitGitGadget
2019-07-25  9:30     ` Johannes Schindelin
2019-07-25  2:23   ` [PATCH v2 2/5] repo-settings: add feature.manyCommits setting Derrick Stolee via GitGitGadget
2019-07-25  2:23   ` Derrick Stolee via GitGitGadget [this message]
2019-07-25  9:36     ` [PATCH v2 3/5] repo-settings: parse core.untrackedCache Johannes Schindelin
2019-07-25  2:23   ` [PATCH v2 4/5] repo-settings: create feature.manyFiles setting Derrick Stolee via GitGitGadget
2019-07-25  2:23   ` [PATCH v2 5/5] repo-settings: create feature.experimental setting Derrick Stolee via GitGitGadget
2019-07-25  9:40   ` [PATCH v2 0/5] Create 'feature.*' config area and some centralized config parsing Johannes Schindelin
2019-07-30 19:35   ` [PATCH v3 " Derrick Stolee via GitGitGadget
2019-07-30 19:35     ` [PATCH v3 1/5] repo-settings: consolidate some config settings Derrick Stolee via GitGitGadget
2019-07-30 20:47       ` Junio C Hamano
2019-07-30 19:35     ` [PATCH v3 2/5] repo-settings: add feature.manyCommits setting Derrick Stolee via GitGitGadget
2019-07-30 20:57       ` Junio C Hamano
2019-07-31 13:17         ` Johannes Schindelin
2019-07-31 15:48           ` Junio C Hamano
2019-07-31 15:01       ` Ævar Arnfjörð Bjarmason
2019-08-01 18:27         ` Derrick Stolee
2019-07-30 19:35     ` [PATCH v3 4/5] repo-settings: create feature.manyFiles setting Derrick Stolee via GitGitGadget
2019-07-30 19:35     ` [PATCH v3 3/5] repo-settings: parse core.untrackedCache Derrick Stolee via GitGitGadget
2019-07-30 19:35     ` [PATCH v3 5/5] repo-settings: create feature.experimental setting Derrick Stolee via GitGitGadget
2019-08-08 18:34       ` Elijah Newren
2019-08-08 18:48         ` Derrick Stolee
2019-08-08 18:59         ` Junio C Hamano
2019-08-08 19:12           ` Derrick Stolee
2019-08-08 20:31             ` Elijah Newren
2019-08-08 20:49               ` Derrick Stolee
2019-08-08 19:19           ` Elijah Newren
2019-08-08 20:07             ` Junio C Hamano
2019-08-08 20:46               ` Derrick Stolee
2019-08-13 18:37     ` [PATCH v4 0/6] Create 'feature.*' config area and some centralized config parsing Derrick Stolee via GitGitGadget
2019-08-13 18:37       ` [PATCH v4 1/6] repo-settings: consolidate some config settings Derrick Stolee via GitGitGadget
2019-08-13 18:37       ` [PATCH v4 2/6] t6501: use 'git gc' in quiet mode Derrick Stolee via GitGitGadget
2019-08-13 18:37       ` [PATCH v4 3/6] commit-graph: turn on commit-graph by default Derrick Stolee via GitGitGadget
2021-09-20  0:42         ` Junio C Hamano
2021-09-20  1:22           ` Ævar Arnfjörð Bjarmason
2021-09-20  1:25           ` brian m. carlson
2021-09-20 12:53             ` Phillip Wood
2021-09-20 13:30               ` Ævar Arnfjörð Bjarmason
2021-09-20 18:00                 ` Phillip Wood
2021-09-20 19:18                 ` Jeff King
2019-08-13 18:37       ` [PATCH v4 4/6] repo-settings: parse core.untrackedCache Derrick Stolee via GitGitGadget
2019-08-13 18:37       ` [PATCH v4 5/6] repo-settings: create feature.manyFiles setting Derrick Stolee via GitGitGadget
2019-08-13 18:37       ` [PATCH v4 6/6] repo-settings: create feature.experimental setting Derrick Stolee via GitGitGadget
2019-08-13 21:04       ` [PATCH v4 0/6] Create 'feature.*' config area and some centralized config parsing Junio C Hamano
2019-08-13 21:08         ` Junio C Hamano
2019-08-14 10:32           ` Derrick Stolee
2019-08-14 10:38             ` Derrick Stolee

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=49be7a73454b13b04270531eece87a2c6f6d3189.1564021393.git.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=avarab@gmail.com \
    --cc=carenas@gmail.com \
    --cc=dstolee@microsoft.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jnareb@gmail.com \
    --cc=pclouds@gmail.com \
    --cc=peff@peff.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).