unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: David Bremner <david@tethera.net>
To: David Bremner <david@tethera.net>, notmuch@notmuchmail.org
Subject: [PATCH 4/6] lib/open: use notmuch->params to track split status
Date: Sat, 25 Dec 2021 09:33:03 -0400	[thread overview]
Message-ID: <20211225133305.3014272-2-david@tethera.net> (raw)
In-Reply-To: <20211225133305.3014272-1-david@tethera.net>

Persisting this status will allow us to use the information in other
compilation units, in particular when setting configuration defaults.
---
 lib/database-private.h |  7 ++++++-
 lib/open.cc            | 19 ++++++++-----------
 2 files changed, 14 insertions(+), 12 deletions(-)

diff --git a/lib/database-private.h b/lib/database-private.h
index 8133e364..5db8882f 100644
--- a/lib/database-private.h
+++ b/lib/database-private.h
@@ -191,12 +191,17 @@ operator& (notmuch_field_flag_t a, notmuch_field_flag_t b)
 				    Xapian::QueryParser::FLAG_PURE_NOT)
 
 /*
- * Which parameters were explicit when the database was opened */
+ * explicit and implied parameters to open */
 typedef enum {
     NOTMUCH_PARAM_NONE		= 0,
+    /* database passed explicitely */
     NOTMUCH_PARAM_DATABASE	= 1 << 0,
+    /* config file passed explicitely */
     NOTMUCH_PARAM_CONFIG	= 1 << 1,
+    /* profile name passed explicitely */
     NOTMUCH_PARAM_PROFILE	= 1 << 2,
+    /* split (e.g. XDG) configuration */
+    NOTMUCH_PARAM_SPLIT		= 1 << 3,
 } notmuch_open_param_t;
 
 /*
diff --git a/lib/open.cc b/lib/open.cc
index 320b690e..bf1d7ae3 100644
--- a/lib/open.cc
+++ b/lib/open.cc
@@ -190,7 +190,6 @@ _choose_database_path (notmuch_database_t *notmuch,
 		       const char *profile,
 		       GKeyFile *key_file,
 		       const char **database_path,
-		       bool *split,
 		       char **message)
 {
     if (! *database_path) {
@@ -215,7 +214,7 @@ _choose_database_path (notmuch_database_t *notmuch,
 	if (status) {
 	    *database_path = NULL;
 	} else {
-	    *split = true;
+	    notmuch->params |= NOTMUCH_PARAM_SPLIT;
 	}
     }
 
@@ -513,7 +512,6 @@ notmuch_database_open_with_config (const char *database_path,
     notmuch_database_t *notmuch = NULL;
     char *message = NULL;
     GKeyFile *key_file = NULL;
-    bool split = false;
 
     _notmuch_init ();
 
@@ -530,7 +528,7 @@ notmuch_database_open_with_config (const char *database_path,
     }
 
     if ((status = _choose_database_path (notmuch, profile, key_file,
-					 &database_path, &split,
+					 &database_path,
 					 &message)))
 	goto DONE;
 
@@ -610,7 +608,6 @@ notmuch_database_create_with_config (const char *database_path,
     char *message = NULL;
     GKeyFile *key_file = NULL;
     int err;
-    bool split = false;
 
     _notmuch_init ();
 
@@ -627,7 +624,7 @@ notmuch_database_create_with_config (const char *database_path,
     }
 
     if ((status = _choose_database_path (notmuch, profile, key_file,
-					 &database_path, &split, &message)))
+					 &database_path, &message)))
 	goto DONE;
 
     status = _db_dir_exists (database_path, &message);
@@ -636,18 +633,19 @@ notmuch_database_create_with_config (const char *database_path,
 
     _set_database_path (notmuch, database_path);
 
-    if (key_file && ! split) {
+    if (key_file && ! (notmuch->params & NOTMUCH_PARAM_SPLIT)) {
 	char *mail_root = notmuch_canonicalize_file_name (
 	    g_key_file_get_string (key_file, "database", "mail_root", NULL));
 	char *db_path = notmuch_canonicalize_file_name (database_path);
 
-	split = (mail_root && (0 != strcmp (mail_root, db_path)));
+	if (mail_root && (0 != strcmp (mail_root, db_path)))
+	    notmuch->params |= NOTMUCH_PARAM_SPLIT;
 
 	free (mail_root);
 	free (db_path);
     }
 
-    if (split) {
+    if (notmuch->params & NOTMUCH_PARAM_SPLIT) {
 	notmuch_path = database_path;
     } else {
 	if (! (notmuch_path = talloc_asprintf (notmuch, "%s/%s", database_path, ".notmuch"))) {
@@ -809,7 +807,6 @@ notmuch_database_load_config (const char *database_path,
     notmuch_database_t *notmuch = NULL;
     char *message = NULL;
     GKeyFile *key_file = NULL;
-    bool split = false;
 
     _notmuch_init ();
 
@@ -832,7 +829,7 @@ notmuch_database_load_config (const char *database_path,
     }
 
     status = _choose_database_path (notmuch, profile, key_file,
-				    &database_path, &split, &message);
+				    &database_path, &message);
     switch (status) {
     case NOTMUCH_STATUS_NO_DATABASE:
     case NOTMUCH_STATUS_SUCCESS:
-- 
2.34.1

  reply	other threads:[~2021-12-25 13:33 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-11 12:49 [PATCH 1/2] test/libconfig: save and restore config file David Bremner
2021-12-11 12:49 ` [PATCH 2/2] test/libconfig: add two tests for the config = "" case David Bremner
2021-12-25 13:33   ` [PATCH 3/6] lib/open: use db struct as talloc ctx for choose_database_path David Bremner
2021-12-25 13:33     ` David Bremner [this message]
2021-12-25 13:33     ` [PATCH 5/6] lib/config: make sure the config map exists when loading defaults David Bremner
2021-12-25 13:33     ` [PATCH 6/6] lib/open: no default mail root in split configurations David Bremner
2022-01-16  1:56 ` [PATCH 1/2] test/libconfig: save and restore config file 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=20211225133305.3014272-2-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).