{"thread":{"id":"63617","subject":"[GSOC PATCH 0/2] preload-index: remove dependency on global variables and 'the_repository'","startedAt":"2025-06-10T13:02:54Z","lastAt":"2025-06-10T17:11:58Z","messageCount":4,"participants":["Ayush Chandekar","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"520037","messageId":"cover.1749557133.git.ayu.chandekar@gmail.com","threadId":"63617","inReplyTo":null,"subject":"[GSOC PATCH 0/2] preload-index: remove dependency on global variables and 'the_repository'","fromName":"Ayush Chandekar","fromEmail":"ayu.chandekar@gmail.com","sentAt":"2025-06-10T13:02:19Z","receivedAt":"2025-06-10T13:02:54Z","isPatch":true,"sender":{"key":"ayu.chandekar@gmail.com","avatar":"https://avatars.githubusercontent.com/u/137001939?v=4"},"body":"The aim of this patch series is to remove the definition '#define USE_THE_REPOSITORY_VARIABLE' \nfrom \"preload-index.c\" by removing global variables and the global 'the_repository'.\n\nThis patch series contains two patches:\n\n1 - Remove the global variable 'core_preload_index' and localize it in the function which calls it.\n\n2 - Remove the dependency of 'the_repository' in \"preload-index.c\", allowing the removal of \nthe definition.\n\nRemoving these global variables is part of my GSoC project.\n\nAyush Chandekar (2):\n  environment: remove the global variable 'core_preload_index'\n  preload-index: stop depending on 'the_repository'\n\n config.c        | 5 -----\n environment.c   | 3 ---\n environment.h   | 1 -\n preload-index.c | 7 +++++--\n 4 files changed, 5 insertions(+), 11 deletions(-)\n\n-- \n2.49.0\n\n"},{"id":"520038","messageId":"1dda6c9ab616bcdf5632c0c1359b489844f7933f.1749557133.git.ayu.chandekar@gmail.com","threadId":"63617","inReplyTo":"cover.1749557133.git.ayu.chandekar@gmail.com","subject":"[GSOC PATCH 1/2] environment: remove the global variable 'core_preload_index'","fromName":"Ayush Chandekar","fromEmail":"ayu.chandekar@gmail.com","sentAt":"2025-06-10T13:02:20Z","receivedAt":"2025-06-10T13:03:02Z","isPatch":true,"sender":{"key":"ayu.chandekar@gmail.com","avatar":"https://avatars.githubusercontent.com/u/137001939?v=4"},"body":"The global variable 'core_preload_index' is used in a single function\nnamed 'preload_index()' in \"preload-index.c\". Move its declaration inside\nthat function, removing unnecessary global state.\n\nThis change is part of an ongoing effort to eliminate global variables,\nimprove modularity and help libify the codebase.\n\nMentored-by: Christian Couder <christian.couder@gmail.com>\nMentored-by: Ghanshyam Thakkar <shyamthakkar001@gmail.com>\nSigned-off-by: Ayush Chandekar <ayu.chandekar@gmail.com>\n---\n config.c        | 5 -----\n environment.c   | 3 ---\n environment.h   | 1 -\n preload-index.c | 4 ++++\n 4 files changed, 4 insertions(+), 9 deletions(-)\n\ndiff --git a/config.c b/config.c\nindex b18b5617fc..eb60c293ab 100644\n--- a/config.c\n+++ b/config.c\n@@ -1595,11 +1595,6 @@ static int git_default_core_config(const char *var, const char *value,\n \t\treturn 0;\n \t}\n \n-\tif (!strcmp(var, \"core.preloadindex\")) {\n-\t\tcore_preload_index = git_config_bool(var, value);\n-\t\treturn 0;\n-\t}\n-\n \tif (!strcmp(var, \"core.createobject\")) {\n \t\tif (!value)\n \t\t\treturn config_error_nonbool(var);\ndiff --git a/environment.c b/environment.c\nindex c61d773e7e..7bf0390a33 100644\n--- a/environment.c\n+++ b/environment.c\n@@ -113,9 +113,6 @@ const char *comment_line_str = \"#\";\n char *comment_line_str_to_free;\n int auto_comment_line_char;\n \n-/* Parallel index stat data preload? */\n-int core_preload_index = 1;\n-\n /* This is set by setup_git_directory_gently() and/or git_default_config() */\n char *git_work_tree_cfg;\n \ndiff --git a/environment.h b/environment.h\nindex 3d98461a06..9a3d05d414 100644\n--- a/environment.h\n+++ b/environment.h\n@@ -155,7 +155,6 @@ extern int pack_compression_level;\n extern unsigned long pack_size_limit_cfg;\n extern int max_allowed_tree_depth;\n \n-extern int core_preload_index;\n extern int precomposed_unicode;\n extern int protect_hfs;\n extern int protect_ntfs;\ndiff --git a/preload-index.c b/preload-index.c\nindex 40ab2abafb..9fee4cc3aa 100644\n--- a/preload-index.c\n+++ b/preload-index.c\n@@ -19,6 +19,7 @@\n #include \"repository.h\"\n #include \"symlinks.h\"\n #include \"trace2.h\"\n+#include \"config.h\"\n \n /*\n  * Mostly randomly chosen maximum thread counts: we\n@@ -111,6 +112,9 @@ void preload_index(struct index_state *index,\n \tstruct thread_data data[MAX_PARALLEL];\n \tstruct progress_data pd;\n \tint t2_sum_lstat = 0;\n+\tint core_preload_index = 1;\n+\n+\trepo_config_get_bool(the_repository, \"core.preloadindex\", &core_preload_index);\n \n \tif (!HAVE_THREADS || !core_preload_index)\n \t\treturn;\n-- \n2.49.0\n\n"},{"id":"520039","messageId":"505a6ee8a55397fc5cdfc6f003861f6fefab29d1.1749557133.git.ayu.chandekar@gmail.com","threadId":"63617","inReplyTo":"cover.1749557133.git.ayu.chandekar@gmail.com","subject":"[GSOC PATCH 2/2] preload-index: stop depending on 'the_repository'","fromName":"Ayush Chandekar","fromEmail":"ayu.chandekar@gmail.com","sentAt":"2025-06-10T13:02:21Z","receivedAt":"2025-06-10T13:03:04Z","isPatch":true,"sender":{"key":"ayu.chandekar@gmail.com","avatar":"https://avatars.githubusercontent.com/u/137001939?v=4"},"body":"Refactor \"preload-index.c\" to remove the dependency on the global\n'the_repository'. Replace the occurrences of 'the_repository' with\n'index->repo' and thus remove the definition '#define\nUSE_THE_REPOSITORY_VARIABLE'.\n\nMentored-by: Christian Couder <christian.couder@gmail.com>\nMentored-by: Ghanshyam Thakkar <shyamthakkar001@gmail.com>\nSigned-off-by: Ayush Chandekar <ayu.chandekar@gmail.com>\n---\n preload-index.c | 5 ++---\n 1 file changed, 2 insertions(+), 3 deletions(-)\n\ndiff --git a/preload-index.c b/preload-index.c\nindex 9fee4cc3aa..b222821b44 100644\n--- a/preload-index.c\n+++ b/preload-index.c\n@@ -2,7 +2,6 @@\n  * Copyright (C) 2008 Linus Torvalds\n  */\n \n-#define USE_THE_REPOSITORY_VARIABLE\n #define DISABLE_SIGN_COMPARE_WARNINGS\n \n #include \"git-compat-util.h\"\n@@ -114,7 +113,7 @@ void preload_index(struct index_state *index,\n \tint t2_sum_lstat = 0;\n \tint core_preload_index = 1;\n \n-\trepo_config_get_bool(the_repository, \"core.preloadindex\", &core_preload_index);\n+\trepo_config_get_bool(index->repo, \"core.preloadindex\", &core_preload_index);\n \n \tif (!HAVE_THREADS || !core_preload_index)\n \t\treturn;\n@@ -136,7 +135,7 @@ void preload_index(struct index_state *index,\n \n \tmemset(&pd, 0, sizeof(pd));\n \tif (refresh_flags & REFRESH_PROGRESS && isatty(2)) {\n-\t\tpd.progress = start_delayed_progress(the_repository,\n+\t\tpd.progress = start_delayed_progress(index->repo,\n \t\t\t\t\t\t     _(\"Refreshing index\"),\n \t\t\t\t\t\t     index->cache_nr);\n \t\tpthread_mutex_init(&pd.mutex, NULL);\n-- \n2.49.0\n\n"},{"id":"520053","messageId":"xmqqecvrmsh0.fsf@gitster.g","threadId":"63617","inReplyTo":"cover.1749557133.git.ayu.chandekar@gmail.com","subject":"Re: [GSOC PATCH 0/2] preload-index: remove dependency on global variables and 'the_repository'","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2025-06-10T17:11:55Z","receivedAt":"2025-06-10T17:11:58Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Ayush Chandekar <ayu.chandekar@gmail.com> writes:\n\n> The aim of this patch series is to remove the definition '#define\n> USE_THE_REPOSITORY_VARIABLE' from \"preload-index.c\" by removing\n> global variables and the global 'the_repository'.\n>\n> This patch series contains two patches:\n>\n> 1 - Remove the global variable 'core_preload_index' and localize\n> it in the function which calls it.\n>\n> 2 - Remove the dependency of 'the_repository' in\n> \"preload-index.c\", allowing the removal of the definition.\n>\n> Removing these global variables is part of my GSoC project.\n\nBoth patches are pretty straight-forward and readable.  Will queue.  Thanks.\n"}]}