From: David Bremner <david@tethera.net>
To: notmuch@notmuchmail.org
Cc: David Bremner <david@tethera.net>
Subject: [PATCH 03/19] lib: cache configuration information from database
Date: Sat, 8 Aug 2020 11:16:37 -0300 [thread overview]
Message-ID: <20200808141653.1124111-4-david@tethera.net> (raw)
In-Reply-To: <20200808141653.1124111-1-david@tethera.net>
The main goal is to allow configuration information to be temporarily
overridden by a separate config file.
---
lib/config.cc | 25 +++++++++++++++++++++++++
lib/database-private.h | 3 +++
lib/database.cc | 4 ++++
lib/notmuch-private.h | 3 +++
4 files changed, 35 insertions(+)
diff --git a/lib/config.cc b/lib/config.cc
index dae0ff0e..2d4c3801 100644
--- a/lib/config.cc
+++ b/lib/config.cc
@@ -194,3 +194,28 @@ notmuch_config_list_destroy (notmuch_config_list_t *list)
{
talloc_free (list);
}
+
+notmuch_status_t
+_notmuch_config_load_from_database (notmuch_database_t *notmuch)
+{
+ notmuch_status_t status = NOTMUCH_STATUS_SUCCESS;
+ notmuch_config_list_t *list;
+
+ if (notmuch->config == NULL)
+ notmuch->config = _notmuch_string_map_create (notmuch);
+
+ if (unlikely(notmuch->config == NULL))
+ return NOTMUCH_STATUS_OUT_OF_MEMORY;
+
+ status = notmuch_database_get_config_list (notmuch, "", &list);
+ if (status)
+ return status;
+
+ for (; notmuch_config_list_valid (list); notmuch_config_list_move_to_next (list)) {
+ _notmuch_string_map_append (notmuch->config,
+ notmuch_config_list_key (list),
+ notmuch_config_list_value (list));
+ }
+
+ return status;
+}
diff --git a/lib/database-private.h b/lib/database-private.h
index 041602cd..bfeef869 100644
--- a/lib/database-private.h
+++ b/lib/database-private.h
@@ -226,6 +226,9 @@ struct _notmuch_database {
* here, but at least they are small */
notmuch_string_map_t *user_prefix;
notmuch_string_map_t *user_header;
+
+ /* Cached and possibly overridden configuration */
+ notmuch_string_map_t *config;
};
/* Prior to database version 3, features were implied by the database
diff --git a/lib/database.cc b/lib/database.cc
index acc686c0..350abb11 100644
--- a/lib/database.cc
+++ b/lib/database.cc
@@ -987,6 +987,7 @@ notmuch_database_open_with_config (const char *database_path,
notmuch = talloc_zero (NULL, notmuch_database_t);
notmuch->exception_reported = false;
notmuch->status_string = NULL;
+ notmuch->config = NULL;
notmuch->path = talloc_strdup (notmuch, database_path);
strip_trailing (notmuch->path, '/');
@@ -1085,6 +1086,9 @@ notmuch_database_open_with_config (const char *database_path,
}
}
status = _setup_user_query_fields (notmuch);
+
+ if (status == NOTMUCH_STATUS_SUCCESS)
+ status = _notmuch_config_load_from_database (notmuch);
} catch (const Xapian::Error &error) {
IGNORE_RESULT (asprintf (&message, "A Xapian exception occurred opening database: %s\n",
error.get_msg ().c_str ()));
diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h
index 57ec7f72..0f26b371 100644
--- a/lib/notmuch-private.h
+++ b/lib/notmuch-private.h
@@ -699,6 +699,9 @@ struct _notmuch_indexopts {
#define EMPTY_STRING(s) ((s)[0] == '\0')
+/* config.cc */
+notmuch_status_t
+_notmuch_config_load_from_database (notmuch_database_t * db);
NOTMUCH_END_DECLS
#ifdef __cplusplus
--
2.28.0
next prev parent reply other threads:[~2020-08-08 14:17 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-08 14:16 Initial implementation of merged config David Bremner
2020-08-08 14:16 ` [PATCH 01/19] test: use keys with group 'test' in T590-libconfig David Bremner
2020-08-08 14:16 ` [PATCH 02/19] lib: add stub for notmuch_database_open_with_config David Bremner
2020-08-09 7:19 ` Reto
2020-08-09 10:18 ` David Bremner
2020-08-08 14:16 ` David Bremner [this message]
2020-08-08 14:16 ` [PATCH 04/19] WIP: add notmuch_config_get David Bremner
2020-08-08 14:16 ` [PATCH 05/19] WIP: add notmuch_config_set David Bremner
2020-08-08 14:16 ` [PATCH 06/19] WIP: initial retrieval of database path from config file David Bremner
2020-08-08 14:16 ` [PATCH 07/19] test/libconfig; use n_database_open_with_config David Bremner
2020-08-08 14:16 ` [PATCH 08/19] WIP: add _notmuch_config_load_from_file David Bremner
2020-08-08 14:16 ` [PATCH 09/19] lib: factor out feature name related code David Bremner
2020-08-08 14:16 ` [PATCH 10/19] lib: factor out prefix related code to its own file David Bremner
2020-08-08 14:16 ` [PATCH 11/19] lib: factor out notmuch_database_open* related code to " David Bremner
2020-08-08 14:16 ` [PATCH 12/19] WIP: adding fallbacks for NULL config_path David Bremner
2020-08-08 14:16 ` [PATCH 13/19] lib/config: delay setting talloc destructor David Bremner
2020-08-08 14:16 ` [PATCH 14/19] WIP: add strsplit_len David Bremner
2020-08-08 14:16 ` [PATCH 15/19] WIP: add config values iterator David Bremner
2020-08-08 14:16 ` [PATCH 16/19] test: add regression test for searching with alternate config David Bremner
2020-08-08 14:16 ` [PATCH 17/19] cli/config: add accessor for config file name David Bremner
2020-08-08 14:16 ` [PATCH 18/19] WIP converting notmuch search to new style config David Bremner
2020-08-08 14:16 ` [PATCH 19/19] WIP: switch notmuch-show to new config framework 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=20200808141653.1124111-4-david@tethera.net \
--to=david@tethera.net \
--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).