diff mbox series

[v2,2/5] preload-index: teach GIT_FORCE_PRELOAD_TEST to take a boolean

Message ID 20180914201340.37400-3-benpeart@microsoft.com (mailing list archive)
State New, archived
Headers show
Series [v2,1/5] correct typo/spelling error in t/README | expand

Commit Message

Ben Peart Sept. 14, 2018, 8:14 p.m. UTC
Teach GIT_FORCE_PRELOAD_TEST to take a boolean to turn on or off this test
feature instead of simply testing for existance.

Signed-off-by: Ben Peart <Ben.Peart@microsoft.com>
---
 preload-index.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Jonathan Nieder Sept. 14, 2018, 8:51 p.m. UTC | #1
Ben Peart wrote:

> Subject: preload-index: teach GIT_FORCE_PRELOAD_TEST to take a boolean

Reading this subject line alone (e.g. in "git log --oneline" output),
it's not obvious to me what this patch will do.

What behavior change does it make / what will it make newly possible?

Maybe something like:

	preload-index: use git_env_bool() not getenv() for customization

	GIT_FORCE_PRELOAD_TEST is only checked for presence by using getenv().
	Use git_env_bool() instead so that GIT_FORCE_PRELOAD_TEST=false can
	work as expected.

> Teach GIT_FORCE_PRELOAD_TEST to take a boolean to turn on or off this test
> feature instead of simply testing for existance.
>
> Signed-off-by: Ben Peart <Ben.Peart@microsoft.com>
> ---
>  preload-index.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)

Can you say a little about how this came up?  Was it just noticed
while reading the code, or did it come up in practice?

I wonder if a more useful knob would be a GIT_FORCE_PRELOAD_THREADS
setting, but that's orthogonal to this change.

Thanks and hope that helps,
Jonathan
Junio C Hamano Sept. 14, 2018, 9:54 p.m. UTC | #2
Jonathan Nieder <jrnieder@gmail.com> writes:

> Maybe something like:
>
> 	preload-index: use git_env_bool() not getenv() for customization
>
> 	GIT_FORCE_PRELOAD_TEST is only checked for presence by using getenv().
> 	Use git_env_bool() instead so that GIT_FORCE_PRELOAD_TEST=false can
> 	work as expected.

That is much better description.  Also

	$ cd t && GIT_FORCE_PRELOAD_TEST=t ./t0000-basic.sh

would have allowed us to enable the feature in the older world, but
I suspect it would instead fail the test, saying 't is not a bool
nor int'.

So strictly speaking, it is a backward incompatible change.  I am
not sure if I like it.

>> Teach GIT_FORCE_PRELOAD_TEST to take a boolean to turn on or off this test
>> feature instead of simply testing for existance.

s/existance/existence/?
diff mbox series

Patch

diff --git a/preload-index.c b/preload-index.c
index 71cd2437a3..0a4e2933bb 100644
--- a/preload-index.c
+++ b/preload-index.c
@@ -5,6 +5,7 @@ 
 #include "pathspec.h"
 #include "dir.h"
 #include "fsmonitor.h"
+#include "config.h"
 
 #ifdef NO_PTHREADS
 static void preload_index(struct index_state *index,
@@ -84,7 +85,7 @@  static void preload_index(struct index_state *index,
 		return;
 
 	threads = index->cache_nr / THREAD_COST;
-	if ((index->cache_nr > 1) && (threads < 2) && getenv("GIT_FORCE_PRELOAD_TEST"))
+	if ((index->cache_nr > 1) && (threads < 2) && git_env_bool("GIT_FORCE_PRELOAD_TEST", 0))
 		threads = 2;
 	if (threads < 2)
 		return;