diff mbox series

[RFC,4/5] config.c: refactor configset_iter()

Message ID RFC-patch-4.5-cf224010970-20230317T042408Z-avarab@gmail.com (mailing list archive)
State New, archived
Headers show
Series bypass config.c global state with configset | expand

Commit Message

Ævar Arnfjörð Bjarmason March 17, 2023, 5:01 a.m. UTC
Use variables rather than long lines in configset_iter(), and use our
own "kvi" rather than relying on the global "current_config_kvi"
within this function.

There's no functional change here, but doing this will make a
subsequent functional change smaller.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 config.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)
diff mbox series

Patch

diff --git a/config.c b/config.c
index a65e7bb36d3..230a98b0631 100644
--- a/config.c
+++ b/config.c
@@ -2227,17 +2227,22 @@  static void configset_iter(struct config_set *cs, config_fn_t fn, void *data)
 	struct configset_list *list = &cs->list;
 
 	for (i = 0; i < list->nr; i++) {
+		const char *key;
+		const char *val;
+		struct key_value_info *kvi;
+
 		entry = list->items[i].e;
 		value_index = list->items[i].value_index;
 		values = &entry->value_list;
 
-		current_config_kvi = values->items[value_index].util;
-
-		if (fn(entry->key, values->items[value_index].string, data) < 0)
-			git_die_config_linenr(entry->key,
-					      current_config_kvi->filename,
-					      current_config_kvi->linenr);
+		key = entry->key;
+		val = values->items[value_index].string;
+		kvi = values->items[value_index].util;
 
+		current_config_kvi = kvi;
+		if (fn(key, val, data) < 0)
+			git_die_config_linenr(entry->key, kvi->filename,
+					      kvi->linenr);
 		current_config_kvi = NULL;
 	}
 }