diff mbox series

[RFC,3/5] config API: add a config_origin_type_name() helper

Message ID RFC-patch-3.5-e0055e2865e-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
Add a config_origin_type_name() helper function. In a subsequent
commit we'll want to invoke this part of current_config_origin_type()
without requiring the global "current_config_kvi" or "cf" state.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 config.c | 25 +++++++++++++++----------
 config.h |  6 ++++++
 2 files changed, 21 insertions(+), 10 deletions(-)
diff mbox series

Patch

diff --git a/config.c b/config.c
index a4105c456c3..a65e7bb36d3 100644
--- a/config.c
+++ b/config.c
@@ -3766,17 +3766,8 @@  int parse_config_key(const char *var,
 	return 0;
 }
 
-const char *current_config_origin_type(void)
+const char *config_origin_type_name(enum config_origin_type type)
 {
-	enum config_origin_type type;
-
-	if (current_config_kvi)
-		type = current_config_kvi->origin_type;
-	else if(cf)
-		type = cf->origin_type;
-	else
-		BUG("current_config_origin_type called outside config callback");
-
 	switch (type) {
 	case CONFIG_ORIGIN_BLOB:
 		return "blob";
@@ -3793,6 +3784,20 @@  const char *current_config_origin_type(void)
 	}
 }
 
+const char *current_config_origin_type(void)
+{
+	enum config_origin_type type;
+
+	if (current_config_kvi)
+		type = current_config_kvi->origin_type;
+	else if(cf)
+		type = cf->origin_type;
+	else
+		BUG("current_config_origin_type called outside config callback");
+
+	return config_origin_type_name(type);
+}
+
 const char *config_scope_name(enum config_scope scope)
 {
 	switch (scope) {
diff --git a/config.h b/config.h
index 571b92d674a..a9cb01e9405 100644
--- a/config.h
+++ b/config.h
@@ -117,6 +117,12 @@  struct key_value_info {
 	enum config_scope scope;
 };
 
+/**
+ * Given the "enum config_origin_type origin_type"
+ * (e.g. CONFIG_ORIGIN_BLOB) return a string (e.g. "blob").
+ */
+const char *config_origin_type_name(enum config_origin_type type);
+
 /**
  * A config callback function takes three parameters:
  *