git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Jeff King <peff@peff.net>
To: git@vger.kernel.org
Cc: "Dennis Kaarsemaker" <dennis@kaarsemaker.net>,
	"Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH 16/16] init: reset cached config when entering new repo
Date: Mon, 12 Sep 2016 20:24:23 -0700	[thread overview]
Message-ID: <20160913032422.xy22la6uw23hnvje@sigill.intra.peff.net> (raw)
In-Reply-To: <20160913032242.coyuhyhn6uklewuk@sigill.intra.peff.net>

After we copy the templates into place, we re-read the
config in case we copied in a default config file. But since
git_config() is backed by a cache these days, it's possible
that the call will not actually touch the filesystem at all;
we need to tell it that something has changed behind the
scenes.

Note that we also need to reset the shared_repository
config. At first glance, it seems like this should probably
just be folded into git_config_clear(). But unfortunately
that is not quite right. The shared repository value may
come from config, _or_ it may have been set manually. So
only the caller who knows whether or not they set it is the
one who can clear it (and indeed, if you _do_ put it into
git_config_clear(), then many tests fail, as we have to
clear the config cache any time we set a new config
variable).

There are three tests here. The first two actually pass
already, though it's largely luck: they just don't happen to
actually read any config before we enter the new repo.

But the third one does fail without this patch; we look at
core.sharedrepository while creating the directory, but need
to make sure the value from the template config overrides
it.

Signed-off-by: Jeff King <peff@peff.net>
---
 builtin/init-db.c      |  6 ++++++
 cache.h                |  7 +++++++
 environment.c          |  5 +++++
 t/t1301-shared-repo.sh | 32 ++++++++++++++++++++++++++++++++
 4 files changed, 50 insertions(+)

diff --git a/builtin/init-db.c b/builtin/init-db.c
index e935895..cea4550 100644
--- a/builtin/init-db.c
+++ b/builtin/init-db.c
@@ -195,8 +195,14 @@ static int create_default_files(const char *template_path)
 	 * First copy the templates -- we might have the default
 	 * config file there, in which case we would want to read
 	 * from it after installing.
+	 *
+	 * Before reading that config, we also need to clear out any cached
+	 * values (since we've just potentially changed what's available on
+	 * disk).
 	 */
 	copy_templates(template_path);
+	git_config_clear();
+	reset_shared_repository();
 	git_config(git_default_config, NULL);
 
 	/*
diff --git a/cache.h b/cache.h
index e9592d3..4c8d85b 100644
--- a/cache.h
+++ b/cache.h
@@ -671,8 +671,15 @@ extern size_t delta_base_cache_limit;
 extern unsigned long big_file_threshold;
 extern unsigned long pack_size_limit_cfg;
 
+/*
+ * Accessors for the core.sharedrepository config which lazy-load the value
+ * from the config (if not already set). The "reset" function can be
+ * used to unset "set" or cached value, meaning that the value will be loaded
+ * fresh from the config file on the next call to get_shared_repository().
+ */
 void set_shared_repository(int value);
 int get_shared_repository(void);
+void reset_shared_repository(void);
 
 /*
  * Do replace refs need to be checked this run?  This variable is
diff --git a/environment.c b/environment.c
index c0cce6b..cd5aa57 100644
--- a/environment.c
+++ b/environment.c
@@ -351,3 +351,8 @@ int get_shared_repository(void)
 	}
 	return the_shared_repository;
 }
+
+void reset_shared_repository(void)
+{
+	need_shared_repository_from_config = 1;
+}
diff --git a/t/t1301-shared-repo.sh b/t/t1301-shared-repo.sh
index 7c28642..1312004 100755
--- a/t/t1301-shared-repo.sh
+++ b/t/t1301-shared-repo.sh
@@ -181,4 +181,36 @@ test_expect_success POSIXPERM 'remote init does not use config from cwd' '
 	test_cmp expect actual
 '
 
+test_expect_success POSIXPERM 're-init respects core.sharedrepository (local)' '
+	git config core.sharedrepository 0666 &&
+	umask 0022 &&
+	echo whatever >templates/foo &&
+	git init --template=templates &&
+	echo "-rw-rw-rw-" >expect &&
+	modebits .git/foo >actual &&
+	test_cmp expect actual
+'
+
+test_expect_success POSIXPERM 're-init respects core.sharedrepository (remote)' '
+	rm -rf child.git &&
+	umask 0022 &&
+	git init --bare --shared=0666 child.git &&
+	test_path_is_missing child.git/foo &&
+	git init --bare --template=../templates child.git &&
+	echo "-rw-rw-rw-" >expect &&
+	modebits child.git/foo >actual &&
+	test_cmp expect actual
+'
+
+test_expect_success POSIXPERM 'template can set core.sharedrepository' '
+	rm -rf child.git &&
+	umask 0022 &&
+	git config core.sharedrepository 0666 &&
+	cp .git/config templates/config &&
+	git init --bare --template=../templates child.git &&
+	echo "-rw-rw-rw-" >expect &&
+	modebits child.git/HEAD >actual &&
+	test_cmp expect actual
+'
+
 test_done
-- 
2.10.0.230.g6f8d04b

  parent reply	other threads:[~2016-09-13  3:24 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-13  3:22 [PATCH 0/16] fix config-reading in non-repos Jeff King
2016-09-13  3:23 ` [PATCH 01/16] t1007: factor out repeated setup Jeff King
2016-09-13 21:42   ` Stefan Beller
2016-09-13  3:23 ` [PATCH 02/16] hash-object: always try to set up the git repository Jeff King
2016-09-13  3:23 ` [PATCH 03/16] patch-id: use RUN_SETUP_GENTLY Jeff King
2016-09-13  3:23 ` [PATCH 04/16] diff: skip implicit no-index check when given --no-index Jeff King
2016-09-13  3:23 ` [PATCH 05/16] diff: handle --no-index prefixes consistently Jeff King
2016-09-13  3:23 ` [PATCH 06/16] diff: always try to set up the repository Jeff King
2016-09-13 22:00   ` Stefan Beller
2016-09-13 22:22     ` Jeff King
2016-09-13  3:23 ` [PATCH 07/16] pager: remove obsolete comment Jeff King
2016-09-13  3:23 ` [PATCH 08/16] pager: stop loading git_default_config() Jeff King
2016-09-13  3:23 ` [PATCH 09/16] pager: make pager_program a file-local static Jeff King
2016-09-13  3:23 ` [PATCH 10/16] pager: use callbacks instead of configset Jeff King
2016-09-13  3:23 ` [PATCH 11/16] pager: handle early config Jeff King
2016-09-13  3:24 ` [PATCH 12/16] t1302: use "git -C" Jeff King
2016-09-13  3:24 ` [PATCH 13/16] test-config: setup git directory Jeff King
2016-09-13  3:24 ` [PATCH 14/16] config: only read .git/config from configured repos Jeff King
2016-09-13  3:24 ` [PATCH 15/16] init: expand comments explaining config trickery Jeff King
2016-09-13  3:24 ` Jeff King [this message]
2016-09-13 22:18   ` [PATCH 16/16] init: reset cached config when entering new repo Stefan Beller
2016-09-14 10:55 ` [PATCH 0/16] fix config-reading in non-repos Dennis Kaarsemaker
2016-09-14 15:31   ` Jeff King

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=20160913032422.xy22la6uw23hnvje@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=dennis@kaarsemaker.net \
    --cc=git@vger.kernel.org \
    --cc=pclouds@gmail.com \
    /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).