environment: remove the global variable 'core_preload_index'
The global variable 'core_preload_index' is used in a single function named 'preload_index()' in "preload-index.c". Move its declaration inside that function, removing unnecessary global state. This change is part of an ongoing effort to eliminate global variables, improve modularity and help libify the codebase. Mentored-by: Christian Couder <christian.couder@gmail.com> Mentored-by: Ghanshyam Thakkar <shyamthakkar001@gmail.com> Signed-off-by: Ayush Chandekar <ayu.chandekar@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Ayush Chandekar committed
Jun 10, 2025 at 18:32 UTC
b1d47b464e553331c555f122c5e341dfbfb618bd
4 files changed
+4
-9
config.c
-5
@@ -1595,11 +1595,6 @@ static int git_default_core_config(const char *var, const char *value,
1595
return 0;
1596
}
1597
1598
- if (!strcmp(var, "core.preloadindex")) {
1599
- core_preload_index = git_config_bool(var, value);
1600
- return 0;
1601
- }
1602
-
1598
if (!strcmp(var, "core.createobject")) {
1599
if (!value)
1600
return config_error_nonbool(var);
environment.c
-3
@@ -113,9 +113,6 @@ const char *comment_line_str = "#";
113
char *comment_line_str_to_free;
114
int auto_comment_line_char;
115
116
-/* Parallel index stat data preload? */
117
-int core_preload_index = 1;
118
-
116
/* This is set by setup_git_directory_gently() and/or git_default_config() */
117
char *git_work_tree_cfg;
118
environment.h
-1
@@ -155,7 +155,6 @@ extern int pack_compression_level;
155
extern unsigned long pack_size_limit_cfg;
156
extern int max_allowed_tree_depth;
157
158
-extern int core_preload_index;
158
extern int precomposed_unicode;
159
extern int protect_hfs;
160
extern int protect_ntfs;
preload-index.c
+4
@@ -19,6 +19,7 @@
19
#include "repository.h"
20
#include "symlinks.h"
21
#include "trace2.h"
22
+#include "config.h"
23
24
/*
25
* Mostly randomly chosen maximum thread counts: we
@@ -111,6 +112,9 @@ void preload_index(struct index_state *index,
112
struct thread_data data[MAX_PARALLEL];
113
struct progress_data pd;
114
int t2_sum_lstat = 0;
115
+ int core_preload_index = 1;
116
+
117
+ repo_config_get_bool(the_repository, "core.preloadindex", &core_preload_index);
118
119
if (!HAVE_THREADS || !core_preload_index)
120
return;