git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] environment: move diff_auto_refresh_index into repo_config_values

From
EGEbele Lynda Okolo via GitGitGadget <gitgitgadget@gmail.com>
Date
Nov 2, 2026, 08:15 UTC
Message-ID
<pull.2289.git.1793607304156.gitgitgadget@gmail.com>
From: Lynndabel <okolo.ebelelynda@gmail.com>

The diff_auto_refresh_index variable is currently a global, which makes it difficult to use Git as a library since global state can't be isolated between different repository instances.

Move it into repo_config_values so that each repository can have its own setting. This follows the pattern used for other recently migrated config options like trust_executable_bit.

Add a getter function repo_diff_auto_refresh_index() that returns the value from the repo's config, falling back to 1 (the default) if the repo isn't initialized yet.

Update the config handler to write to the repo config struct, remove the global variable declaration, and update the caller in builtin/diff.c to use the new getter function.

Add tests to verify the configuration can be set to both true and false without errors.

Signed-off-by: Lynndabel <okolo.ebelelynda@gmail.com>
---
    [Outreachy] diff: move diff_auto_refresh_index to repo_config_values
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-2289%2FLynndabel%2Foutreachy-contribution-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2289/Lynndabel/outreachy-contribution-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/2289
 builtin/diff.c         |  3 ++-
 diff.c                 |  4 ++--
 diff.h                 |  2 --
 environment.c          | 10 ++++++++++
 environment.h          |  5 +++++
 t/t4000-diff-format.sh | 10 ++++++++++
 6 files changed, 29 insertions(+), 5 deletions(-)
diff --git a/builtin/diff.c b/builtin/diff.c
index 18b1083e98..ed83959921 100644
--- a/builtin/diff.c
+++ b/builtin/diff.c
@@ -10,6 +10,7 @@
 #include "builtin.h"
 #include "config.h"
 #include "ewah/ewok.h"
+#include "environment.h"
 #include "lockfile.h"
 #include "color.h"
 #include "commit.h"
@@ -522,7 +523,7 @@ int cmd_diff(int argc,
 	 * Otherwise, we are doing the usual "git" diff; set up any
 	 * further defaults that apply to regular diffs.
 	 */
-	rev.diffopt.skip_stat_unmatch = !!diff_auto_refresh_index;
+	rev.diffopt.skip_stat_unmatch = !!repo_diff_auto_refresh_index(the_repository);
 
 	/*
 	 * Default to intent-to-add entries invisible in the
diff --git a/diff.c b/diff.c
index b4ac17f8ef..5f34ce91a9 100644
--- a/diff.c
+++ b/diff.c
@@ -65,7 +65,6 @@ static unsigned int diff_interhunk_context_default;
 static char *diff_word_regex_cfg;
 static struct external_diff external_diff_cfg;
 static char *diff_order_file_cfg;
-int diff_auto_refresh_index = 1;
 static int diff_mnemonic_prefix;
 static int diff_no_prefix;
 static char *diff_src_prefix;
@@ -400,7 +399,8 @@ int git_diff_ui_config(const char *var, const char *value,
 		return 0;
 	}
 	if (!strcmp(var, "diff.autorefreshindex")) {
-		diff_auto_refresh_index = git_config_bool(var, value);
+		struct repo_config_values *cfg = repo_config_values(the_repository);
+		cfg->diff_auto_refresh_index = git_config_bool(var, value);
 		return 0;
 	}
 	if (!strcmp(var, "diff.mnemonicprefix")) {
diff --git a/diff.h b/diff.h
index bb5cddaf34..466a1230a7 100644
--- a/diff.h
+++ b/diff.h
@@ -767,6 +767,4 @@ void print_stat_summary(FILE *fp, int files,
 			int insertions, int deletions);
 void setup_diff_pager(struct diff_options *);
 
-extern int diff_auto_refresh_index;
-
 #endif /* DIFF_H */
diff --git a/environment.c b/environment.c
index c83cf44839..2947e558d4 100644
--- a/environment.c
+++ b/environment.c
@@ -152,6 +152,13 @@ int repo_has_symlinks(struct repository *repo)
 		: platform_has_symlinks();
 }
 
+int repo_diff_auto_refresh_index(struct repository *repo)
+{
+	return repo->initialized
+		? repo_config_values(repo)->diff_auto_refresh_index
+		: 1;
+}
+
 const char *repo_excludes_file(struct repository *repo)
 {
 	struct repo_config_values *cfg = repo_config_values(repo);
@@ -778,6 +785,9 @@ void repo_config_values_init(struct repo_config_values *cfg)
 	cfg->has_symlinks = platform_has_symlinks();
 	cfg->use_nanosec = 0;
 
+	/* section "diff" config values */
+	cfg->diff_auto_refresh_index = 1;
+
 	/* section "sparse" config values */
 	cfg->sparse_expect_files_outside_of_patterns = 0;
 
diff --git a/environment.h b/environment.h
index 49c86e8879..b6304d2e5c 100644
--- a/environment.h
+++ b/environment.h
@@ -150,6 +150,9 @@ struct repo_config_values {
 	int has_symlinks;
 	int use_nanosec;
 
+	/* section "diff" config values */
+	int diff_auto_refresh_index;
+
 	/* section "sparse" config values */
 	int sparse_expect_files_outside_of_patterns;
 
@@ -203,6 +206,8 @@ int repo_trust_executable_bit(struct repository *repo);
 
 int repo_has_symlinks(struct repository *repo);
 
+int repo_diff_auto_refresh_index(struct repository *repo);
+
 const char *repo_excludes_file(struct repository *repo);
 
 void repo_config_values_init(struct repo_config_values *cfg);
diff --git a/t/t4000-diff-format.sh b/t/t4000-diff-format.sh
index 74dec7d34a..1fa98d1456 100755
--- a/t/t4000-diff-format.sh
+++ b/t/t4000-diff-format.sh
@@ -122,4 +122,14 @@ do
 	'
 done
 
+test_expect_success 'diff.autorefreshindex can be set to false' '
+	test_config diff.autorefreshindex false &&
+	git diff-files
+'
+
+test_expect_success 'diff.autorefreshindex can be set to true' '
+	test_config diff.autorefreshindex true &&
+	git diff-files
+'
+
 test_done

base-commit: 50fe5cc63f9cd6e89b87a2c9ccf96a444f4cfdb7
-- 
gitgitgadget
Next: Junio C Hamano
Message 1 of 2 in “environment: move diff_auto_refresh_index into repo_config_values”
  1. environment: move diff_auto_refresh_index into repo_config_valuesEbele Lynda Okolo via GitGitGadget, Nov 2, 2026
  2. Junio C HamanoNov 3, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.