Thread (51 messages) flat view 51 messages, 6 authors, 2016-06-15

Re: [PATCH v6 28/32] config: read ref storage config on startup

From: Jeff King <hidden>
Date: 2016-06-15 23:08:33
Subsystem: the rest · Maintainer: Linus Torvalds

On Mon, Feb 29, 2016 at 05:10:24PM -0500, Jeff King wrote:
quoted
We apparently don't always call check_repo_format before calling
git_config_early -- or, more to the point, before doing ref operations.
So I think we need this in git_config_early.
That seems horribly broken, though. If a program is accessing refs
without calling check_repository_format, isn't it bypassing all of our
regular version and extension checks?

I think we should be smoking out such cases (e.g., by setting
a null refs-backend, as I mentioned earlier) and fixing them, rather
than working around them by putting the backend setup in the wrong
place.
So even without your series, this isn't too bad to instrument, like the
patch below.

It does reveal a handful of failures in the test suite. I haven't dug
yet, but I strongly suspect those are all bugs that should be fixed.
diff --git a/cache.h b/cache.h
index af2aeb8..a286f99 100644
--- a/cache.h
+++ b/cache.h
@@ -639,6 +639,7 @@ extern int hold_locked_index(struct lock_file *, int);
 extern void set_alternate_index_output(const char *);
 
 /* Environment bits from configuration mechanism */
+extern int repo_initialized;
 extern int trust_executable_bit;
 extern int trust_ctime;
 extern int check_stat;
diff --git a/environment.c b/environment.c
index 10451ee..6ee9812 100644
--- a/environment.c
+++ b/environment.c
@@ -12,6 +12,7 @@
 #include "fmt-merge-msg.h"
 #include "commit.h"
 
+int repo_initialized;
 int trust_executable_bit = 1;
 int trust_ctime = 1;
 int check_stat = 1;
diff --git a/refs/files-backend.c b/refs/files-backend.c
index 339f5c7..a4e9df6 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -947,6 +947,9 @@ static struct ref_cache *lookup_ref_cache(const char *submodule)
 {
 	struct ref_cache *refs;
 
+	if (!repo_initialized)
+		die("BUG: lookup_ref_cache called without initializing repo");
+
 	if (!submodule || !*submodule)
 		return &ref_cache;
 
@@ -1414,6 +1417,9 @@ static const char *resolve_ref_1(const char *refname,
 	int depth = MAXDEPTH;
 	int bad_name = 0;
 
+	if (!repo_initialized)
+		die("BUG: resolve_ref called without initializing repo");
+
 	if (flags)
 		*flags = 0;
 
diff --git a/setup.c b/setup.c
index 76609fa..ed86094 100644
--- a/setup.c
+++ b/setup.c
@@ -446,6 +446,9 @@ static int check_repository_format_gently(const char *gitdir, int *nongit_ok)
 		ret = -1;
 	}
 
+	if (ret == 0)
+		repo_initialized = 1;
+
 	strbuf_release(&sb);
 	return ret;
 }
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help