All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] environment: move diff_auto_refresh_index into repo_config_values
@ 2026-11-02  8:15 Ebele Lynda Okolo via GitGitGadget
  2026-11-03  6:21 ` Junio C Hamano
  0 siblings, 1 reply; 2+ messages in thread
From: Ebele Lynda Okolo via GitGitGadget @ 2026-11-02  8:15 UTC (permalink / raw)
  To: git; +Cc: Patrick Steinhardt, Usman Akinyemi, Ebele Lynda Okolo, Lynndabel

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

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] environment: move diff_auto_refresh_index into repo_config_values
  2026-11-02  8:15 [PATCH] environment: move diff_auto_refresh_index into repo_config_values Ebele Lynda Okolo via GitGitGadget
@ 2026-11-03  6:21 ` Junio C Hamano
  0 siblings, 0 replies; 2+ messages in thread
From: Junio C Hamano @ 2026-11-03  6:21 UTC (permalink / raw)
  To: Ebele Lynda Okolo via GitGitGadget
  Cc: git, Patrick Steinhardt, Usman Akinyemi, Ebele Lynda Okolo

"Ebele Lynda Okolo via GitGitGadget" <gitgitgadget@gmail.com>
writes:

> 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.

We do not want to put it in repo_config_value, because access to the
structure will barf when given anything other than the_repository,
hence such a move does not help the "library" scene very much to
begin with.

It is only set in diff.c when the ui related configuration variable
is read from the git_config() callback.  The callback is *not*
repository specific but is a synthesized computation result after
reading system, global, and repository configuration files, which is
another reason why it does not look like a good idea to tie this
setting to repo_config_values.

Thanks.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-03  6:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-02  8:15 [PATCH] environment: move diff_auto_refresh_index into repo_config_values Ebele Lynda Okolo via GitGitGadget
2026-11-03  6:21 ` Junio C Hamano

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.