{"thread":{"id":"66743","subject":"[PATCH] environment: move diff_auto_refresh_index into repo_config_values","startedAt":"2026-11-02T08:15:04Z","lastAt":"2026-11-03T06:21:14Z","messageCount":2,"participants":["Ebele Lynda Okolo via GitGitGadget","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"557119","messageId":"pull.2289.git.1793607304156.gitgitgadget@gmail.com","threadId":"66743","inReplyTo":null,"subject":"[PATCH] environment: move diff_auto_refresh_index into repo_config_values","fromName":"Ebele Lynda Okolo via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2026-11-02T08:15:04Z","receivedAt":"2026-11-02T08:15:04Z","isPatch":true,"sender":{"key":"name:Ebele Lynda Okolo","avatar":null},"body":"From: Lynndabel <okolo.ebelelynda@gmail.com>\n\nThe diff_auto_refresh_index variable is currently a global,\nwhich makes it difficult to use Git as a library since\nglobal state can't be isolated between different repository\ninstances.\n\nMove it into repo_config_values so that each repository can\nhave its own setting. This follows the pattern used for other\nrecently migrated config options like trust_executable_bit.\n\nAdd a getter function repo_diff_auto_refresh_index() that\nreturns the value from the repo's config, falling back to 1\n(the default) if the repo isn't initialized yet.\n\nUpdate the config handler to write to the repo config struct,\nremove the global variable declaration, and update the caller\nin builtin/diff.c to use the new getter function.\n\nAdd tests to verify the configuration can be set to both true\nand false without errors.\n\nSigned-off-by: Lynndabel <okolo.ebelelynda@gmail.com>\n---\n    [Outreachy] diff: move diff_auto_refresh_index to repo_config_values\n\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-2289%2FLynndabel%2Foutreachy-contribution-v1\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2289/Lynndabel/outreachy-contribution-v1\nPull-Request: https://github.com/gitgitgadget/git/pull/2289\n\n builtin/diff.c         |  3 ++-\n diff.c                 |  4 ++--\n diff.h                 |  2 --\n environment.c          | 10 ++++++++++\n environment.h          |  5 +++++\n t/t4000-diff-format.sh | 10 ++++++++++\n 6 files changed, 29 insertions(+), 5 deletions(-)\n\ndiff --git a/builtin/diff.c b/builtin/diff.c\nindex 18b1083e98..ed83959921 100644\n--- a/builtin/diff.c\n+++ b/builtin/diff.c\n@@ -10,6 +10,7 @@\n #include \"builtin.h\"\n #include \"config.h\"\n #include \"ewah/ewok.h\"\n+#include \"environment.h\"\n #include \"lockfile.h\"\n #include \"color.h\"\n #include \"commit.h\"\n@@ -522,7 +523,7 @@ int cmd_diff(int argc,\n \t * Otherwise, we are doing the usual \"git\" diff; set up any\n \t * further defaults that apply to regular diffs.\n \t */\n-\trev.diffopt.skip_stat_unmatch = !!diff_auto_refresh_index;\n+\trev.diffopt.skip_stat_unmatch = !!repo_diff_auto_refresh_index(the_repository);\n \n \t/*\n \t * Default to intent-to-add entries invisible in the\ndiff --git a/diff.c b/diff.c\nindex b4ac17f8ef..5f34ce91a9 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -65,7 +65,6 @@ static unsigned int diff_interhunk_context_default;\n static char *diff_word_regex_cfg;\n static struct external_diff external_diff_cfg;\n static char *diff_order_file_cfg;\n-int diff_auto_refresh_index = 1;\n static int diff_mnemonic_prefix;\n static int diff_no_prefix;\n static char *diff_src_prefix;\n@@ -400,7 +399,8 @@ int git_diff_ui_config(const char *var, const char *value,\n \t\treturn 0;\n \t}\n \tif (!strcmp(var, \"diff.autorefreshindex\")) {\n-\t\tdiff_auto_refresh_index = git_config_bool(var, value);\n+\t\tstruct repo_config_values *cfg = repo_config_values(the_repository);\n+\t\tcfg->diff_auto_refresh_index = git_config_bool(var, value);\n \t\treturn 0;\n \t}\n \tif (!strcmp(var, \"diff.mnemonicprefix\")) {\ndiff --git a/diff.h b/diff.h\nindex bb5cddaf34..466a1230a7 100644\n--- a/diff.h\n+++ b/diff.h\n@@ -767,6 +767,4 @@ void print_stat_summary(FILE *fp, int files,\n \t\t\tint insertions, int deletions);\n void setup_diff_pager(struct diff_options *);\n \n-extern int diff_auto_refresh_index;\n-\n #endif /* DIFF_H */\ndiff --git a/environment.c b/environment.c\nindex c83cf44839..2947e558d4 100644\n--- a/environment.c\n+++ b/environment.c\n@@ -152,6 +152,13 @@ int repo_has_symlinks(struct repository *repo)\n \t\t: platform_has_symlinks();\n }\n \n+int repo_diff_auto_refresh_index(struct repository *repo)\n+{\n+\treturn repo->initialized\n+\t\t? repo_config_values(repo)->diff_auto_refresh_index\n+\t\t: 1;\n+}\n+\n const char *repo_excludes_file(struct repository *repo)\n {\n \tstruct repo_config_values *cfg = repo_config_values(repo);\n@@ -778,6 +785,9 @@ void repo_config_values_init(struct repo_config_values *cfg)\n \tcfg->has_symlinks = platform_has_symlinks();\n \tcfg->use_nanosec = 0;\n \n+\t/* section \"diff\" config values */\n+\tcfg->diff_auto_refresh_index = 1;\n+\n \t/* section \"sparse\" config values */\n \tcfg->sparse_expect_files_outside_of_patterns = 0;\n \ndiff --git a/environment.h b/environment.h\nindex 49c86e8879..b6304d2e5c 100644\n--- a/environment.h\n+++ b/environment.h\n@@ -150,6 +150,9 @@ struct repo_config_values {\n \tint has_symlinks;\n \tint use_nanosec;\n \n+\t/* section \"diff\" config values */\n+\tint diff_auto_refresh_index;\n+\n \t/* section \"sparse\" config values */\n \tint sparse_expect_files_outside_of_patterns;\n \n@@ -203,6 +206,8 @@ int repo_trust_executable_bit(struct repository *repo);\n \n int repo_has_symlinks(struct repository *repo);\n \n+int repo_diff_auto_refresh_index(struct repository *repo);\n+\n const char *repo_excludes_file(struct repository *repo);\n \n void repo_config_values_init(struct repo_config_values *cfg);\ndiff --git a/t/t4000-diff-format.sh b/t/t4000-diff-format.sh\nindex 74dec7d34a..1fa98d1456 100755\n--- a/t/t4000-diff-format.sh\n+++ b/t/t4000-diff-format.sh\n@@ -122,4 +122,14 @@ do\n \t'\n done\n \n+test_expect_success 'diff.autorefreshindex can be set to false' '\n+\ttest_config diff.autorefreshindex false &&\n+\tgit diff-files\n+'\n+\n+test_expect_success 'diff.autorefreshindex can be set to true' '\n+\ttest_config diff.autorefreshindex true &&\n+\tgit diff-files\n+'\n+\n test_done\n\nbase-commit: 50fe5cc63f9cd6e89b87a2c9ccf96a444f4cfdb7\n-- \ngitgitgadget\n\n"},{"id":"557264","messageId":"xmqqtslybfl1.fsf@gitster.g","threadId":"66743","inReplyTo":"pull.2289.git.1793607304156.gitgitgadget@gmail.com","subject":"Re: [PATCH] environment: move diff_auto_refresh_index into repo_config_values","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-11-03T06:21:14Z","receivedAt":"2026-11-03T06:21:14Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Ebele Lynda Okolo via GitGitGadget\" <gitgitgadget@gmail.com>\nwrites:\n\n> From: Lynndabel <okolo.ebelelynda@gmail.com>\n>\n> The diff_auto_refresh_index variable is currently a global,\n> which makes it difficult to use Git as a library since\n> global state can't be isolated between different repository\n> instances.\n\nWe do not want to put it in repo_config_value, because access to the\nstructure will barf when given anything other than the_repository,\nhence such a move does not help the \"library\" scene very much to\nbegin with.\n\nIt is only set in diff.c when the ui related configuration variable\nis read from the git_config() callback.  The callback is *not*\nrepository specific but is a synthesized computation result after\nreading system, global, and repository configuration files, which is\nanother reason why it does not look like a good idea to tie this\nsetting to repo_config_values.\n\nThanks.\n\n"}]}