[PATCH 1/7] cli/config: refactor _stored_in_db
David Bremner
david at tethera.net
Sat Mar 2 07:41:27 PST 2019
This will make it easier to add other prefixes that are stored in the
database, compared to special casing each one as "query." was.
---
notmuch-config.c | 21 +++++++++++++++------
1 file changed, 15 insertions(+), 6 deletions(-)
diff --git a/notmuch-config.c b/notmuch-config.c
index bf77cc9d..1517d0ff 100644
--- a/notmuch-config.c
+++ b/notmuch-config.c
@@ -821,17 +821,26 @@ _item_split (char *item, char **group, char **key)
#define BUILT_WITH_PREFIX "built_with."
+struct config_key {
+ const char *name;
+ bool prefix;
+};
+
static bool
_stored_in_db (const char *item)
{
- const char * db_configs[] = {
- "index.decrypt",
+ struct config_key db_configs[] = {
+ {"index.decrypt", false},
+ {"query.", true},
};
- if (STRNCMP_LITERAL (item, "query.") == 0)
- return true;
- for (size_t i = 0; i < ARRAY_SIZE (db_configs); i++)
- if (strcmp (item, db_configs[i]) == 0)
+ for (size_t i = 0; i < ARRAY_SIZE (db_configs); i++) {
+ if (db_configs[i].prefix &&
+ strncmp (item, db_configs[i].name,
+ strlen(db_configs[i].name)) == 0)
return true;
+ if (strcmp (item, db_configs[i].name) == 0)
+ return true;
+ }
return false;
}
--
2.20.1
More information about the notmuch
mailing list