From: andreas@rammhold.de
To: notmuch@notmuchmail.org
Cc: Andreas Rammhold <andreas@rammhold.de>
Subject: [RFC 1/2] lib/config: introduce notmuch_config_values_from_string function
Date: Thu, 16 Sep 2021 12:25:16 +0200 [thread overview]
Message-ID: <20210916102517.1744389-2-andreas@rammhold.de> (raw)
In-Reply-To: <20210916102517.1744389-1-andreas@rammhold.de>
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
next prev parent reply other threads:[~2021-09-16 11:39 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-16 10:25 [RFC 0/2] add --new-tags= to notmuch-new(1) andreas
2021-09-16 10:25 ` andreas [this message]
2021-09-16 10:25 ` [RFC 2/2] CLI/notmuch: add --new-tags argument " andreas
2021-09-16 12:03 ` [RFC 0/2] add --new-tags= " Michael J Gruber
2021-09-16 12:24 ` andreas
2021-09-16 14:43 ` Michael J Gruber
2021-09-20 23:57 ` David Bremner
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
List information: https://notmuchmail.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210916102517.1744389-2-andreas@rammhold.de \
--to=andreas@rammhold.de \
--cc=notmuch@notmuchmail.org \
/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.
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).