From: "Ebele Lynda Okolo via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Patrick Steinhardt <ps@pks.im>,
Usman Akinyemi <usmanakinyemi202@gmail.com>,
Ebele Lynda Okolo <okolo.ebelelynda@gmail.com>,
Lynndabel <okolo.ebelelynda@gmail.com>
Subject: [PATCH] environment: move diff_auto_refresh_index into repo_config_values
Date: Mon, 02 Nov 2026 08:15:04 +0000 [thread overview]
Message-ID: <pull.2289.git.1793607304156.gitgitgadget@gmail.com> (raw)
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 reply other threads:[~2026-11-02 8:15 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-02 8:15 Ebele Lynda Okolo via GitGitGadget [this message]
2026-11-03 6:21 ` [PATCH] environment: move diff_auto_refresh_index into repo_config_values Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=pull.2289.git.1793607304156.gitgitgadget@gmail.com \
--to=gitgitgadget@gmail.com \
--cc=git@vger.kernel.org \
--cc=okolo.ebelelynda@gmail.com \
--cc=ps@pks.im \
--cc=usmanakinyemi202@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox