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 3/6] lib/open: use db struct as talloc ctx for choose_database_path
Date: Sat, 25 Dec 2021 09:33:02 -0400	[thread overview]
Message-ID: <20211225133305.3014272-1-david@tethera.net> (raw)
In-Reply-To: <20211211124912.1823559-2-david@tethera.net>

The extra talloc struct "local" was left over from before the notmuch
struct was allocated earlier. Having the notmuch struct available in
this function will allow more flexibility to track the configuration
variations (e.g. split vs. non-split).
---
 lib/open.cc | 27 +++++++++------------------
 1 file changed, 9 insertions(+), 18 deletions(-)

diff --git a/lib/open.cc b/lib/open.cc
index a91d22ef..320b690e 100644
--- a/lib/open.cc
+++ b/lib/open.cc
@@ -186,7 +186,7 @@ _db_dir_exists (const char *database_path, char **message)
 }
 
 static notmuch_status_t
-_choose_database_path (void *ctx,
+_choose_database_path (notmuch_database_t *notmuch,
 		       const char *profile,
 		       GKeyFile *key_file,
 		       const char **database_path,
@@ -201,16 +201,16 @@ _choose_database_path (void *ctx,
 	char *path = g_key_file_get_string (key_file, "database", "path", NULL);
 	if (path) {
 	    if (path[0] == '/')
-		*database_path = talloc_strdup (ctx, path);
+		*database_path = talloc_strdup (notmuch, path);
 	    else
-		*database_path = talloc_asprintf (ctx, "%s/%s", getenv ("HOME"), path);
+		*database_path = talloc_asprintf (notmuch, "%s/%s", getenv ("HOME"), path);
 	    g_free (path);
 	}
     }
     if (! *database_path) {
 	notmuch_status_t status;
 
-	*database_path = _xdg_dir (ctx, "XDG_DATA_HOME", ".local/share", profile);
+	*database_path = _xdg_dir (notmuch, "XDG_DATA_HOME", ".local/share", profile);
 	status = _db_dir_exists (*database_path, message);
 	if (status) {
 	    *database_path = NULL;
@@ -226,7 +226,7 @@ _choose_database_path (void *ctx,
     if (! *database_path) {
 	notmuch_status_t status;
 
-	*database_path = talloc_asprintf (ctx, "%s/mail", getenv ("HOME"));
+	*database_path = talloc_asprintf (notmuch, "%s/mail", getenv ("HOME"));
 	status = _db_dir_exists (*database_path, message);
 	if (status) {
 	    *database_path = NULL;
@@ -510,7 +510,6 @@ notmuch_database_open_with_config (const char *database_path,
 				   char **status_string)
 {
     notmuch_status_t status = NOTMUCH_STATUS_SUCCESS;
-    void *local = talloc_new (NULL);
     notmuch_database_t *notmuch = NULL;
     char *message = NULL;
     GKeyFile *key_file = NULL;
@@ -530,7 +529,7 @@ notmuch_database_open_with_config (const char *database_path,
 	goto DONE;
     }
 
-    if ((status = _choose_database_path (local, profile, key_file,
+    if ((status = _choose_database_path (notmuch, profile, key_file,
 					 &database_path, &split,
 					 &message)))
 	goto DONE;
@@ -549,8 +548,6 @@ notmuch_database_open_with_config (const char *database_path,
     status = _finish_open (notmuch, profile, mode, key_file, &message);
 
   DONE:
-    talloc_free (local);
-
     if (key_file)
 	g_key_file_free (key_file);
 
@@ -612,7 +609,6 @@ notmuch_database_create_with_config (const char *database_path,
     const char *notmuch_path = NULL;
     char *message = NULL;
     GKeyFile *key_file = NULL;
-    void *local = talloc_new (NULL);
     int err;
     bool split = false;
 
@@ -630,7 +626,7 @@ notmuch_database_create_with_config (const char *database_path,
 	goto DONE;
     }
 
-    if ((status = _choose_database_path (local, profile, key_file,
+    if ((status = _choose_database_path (notmuch, profile, key_file,
 					 &database_path, &split, &message)))
 	goto DONE;
 
@@ -654,7 +650,7 @@ notmuch_database_create_with_config (const char *database_path,
     if (split) {
 	notmuch_path = database_path;
     } else {
-	if (! (notmuch_path = talloc_asprintf (local, "%s/%s", database_path, ".notmuch"))) {
+	if (! (notmuch_path = talloc_asprintf (notmuch, "%s/%s", database_path, ".notmuch"))) {
 	    status = NOTMUCH_STATUS_OUT_OF_MEMORY;
 	    goto DONE;
 	}
@@ -711,8 +707,6 @@ notmuch_database_create_with_config (const char *database_path,
     }
 
   DONE:
-    talloc_free (local);
-
     if (key_file)
 	g_key_file_free (key_file);
 
@@ -812,7 +806,6 @@ notmuch_database_load_config (const char *database_path,
 			      char **status_string)
 {
     notmuch_status_t status = NOTMUCH_STATUS_SUCCESS, warning = NOTMUCH_STATUS_SUCCESS;
-    void *local = talloc_new (NULL);
     notmuch_database_t *notmuch = NULL;
     char *message = NULL;
     GKeyFile *key_file = NULL;
@@ -838,7 +831,7 @@ notmuch_database_load_config (const char *database_path,
 	goto DONE;
     }
 
-    status = _choose_database_path (local, profile, key_file,
+    status = _choose_database_path (notmuch, profile, key_file,
 				    &database_path, &split, &message);
     switch (status) {
     case NOTMUCH_STATUS_NO_DATABASE:
@@ -874,8 +867,6 @@ notmuch_database_load_config (const char *database_path,
 	goto DONE;
 
   DONE:
-    talloc_free (local);
-
     if (status_string)
 	*status_string = message;
 
-- 
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   ` David Bremner [this message]
2021-12-25 13:33     ` [PATCH 4/6] lib/open: use notmuch->params to track split status David Bremner
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-1-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).