From: Andreas Rammhold <andreas@rammhold.de>
This factors out the code required to initialize a
notmuch_config_values_t from a string into a dedicated function. By
exposing this function we can allow consumers (such as notmuch-new(1))
to customize certain configuration values via command line flags.
---
lib/config.cc | 12 +++++++++++-
lib/notmuch.h | 14 ++++++++++++++
test/T590-libconfig.sh | 22 ++++++++++++++++++++++
3 files changed, 47 insertions(+), 1 deletion(-)
diff --git a/lib/config.cc b/lib/config.cc
index 8775b00a..195483a6 100644
--- a/lib/config.cc
+++ b/lib/config.cc
@@ -280,6 +280,16 @@ notmuch_config_get_values (notmuch_database_t *notmuch, notmuch_config_key_t key
notmuch_config_values_t *
notmuch_config_get_values_string (notmuch_database_t *notmuch, const char *key_str)
+{
+ const char * val = _notmuch_string_map_get (notmuch->config, key_str);
+ if (! val)
+ return NULL;
+
+ return notmuch_config_values_from_string (notmuch, val);
+}
+
+notmuch_config_values_t *
+notmuch_config_values_from_string (notmuch_database_t *notmuch, const char *val)
{
notmuch_config_values_t *values = NULL;
bool ok = false;
@@ -290,7 +300,7 @@ notmuch_config_get_values_string (notmuch_database_t *notmuch, const char *key_s
values->children = talloc_new (values);
- values->string = _notmuch_string_map_get (notmuch->config, key_str);
+ values->string = val;
if (! values->string)
goto DONE;
diff --git a/lib/notmuch.h b/lib/notmuch.h
index 546643e8..59dc9dae 100644
--- a/lib/notmuch.h
+++ b/lib/notmuch.h
@@ -2608,6 +2608,20 @@ notmuch_config_get_values (notmuch_database_t *notmuch, notmuch_config_key_t key
notmuch_config_values_t *
notmuch_config_get_values_string (notmuch_database_t *notmuch, const char *key);
+
+/**
+ * Returns an iterator for a ';'-delimited list of configuration values
+ *
+ * @param[in] notmuch database
+ * @param[in] val configuration value
+ *
+ * @since libnotmuch FIXME (notmuch FIXME)
+ *
+ * @retval NULL in case of error.
+ */
+notmuch_config_values_t *
+notmuch_config_values_from_string (notmuch_database_t *notmuch, const char* val);
+
/**
* Is the given 'config_values' iterator pointing at a valid element.
*
diff --git a/test/T590-libconfig.sh b/test/T590-libconfig.sh
index 59b82a6f..3df2ffec 100755
--- a/test/T590-libconfig.sh
+++ b/test/T590-libconfig.sh
@@ -295,6 +295,28 @@ EOF
test_expect_equal_file EXPECTED OUTPUT
restore_database
+test_begin_subtest "notmuch_config_values_from_string"
+cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} ${NOTMUCH_CONFIG} %NULL%
+{
+ notmuch_config_values_t *values = notmuch_config_values_from_string (db, "x;y;z");
+ for (notmuch_config_values_start (values);
+ notmuch_config_values_valid (values);
+ notmuch_config_values_move_to_next (values))
+ {
+ puts (notmuch_config_values_get (values));
+ }
+}
+EOF
+cat <<'EOF' >EXPECTED
+== stdout ==
+x
+y
+z
+== stderr ==
+EOF
+test_expect_equal_file EXPECTED OUTPUT
+restore_database
+
test_begin_subtest "notmuch_config_get_values (restart)"
cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} ${NOTMUCH_CONFIG} %NULL%
{
--
2.32.0
_______________________________________________
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-leave@notmuchmail.org