notmuch.git  about / heads / tags
Unnamed repository; edit this file 'description' to name the repository.
   commit c1c65c34fd200127951af8664107a3d344312345 (patch)
   parent d215a222 WIP: move test for database out of notmuch_command
     tree 1773b44b4124a53443c57886901928c724c51d08
   author David Bremner <david@tethera.net>  2021-02-25 07:59:39 -0400
committer David Bremner <david@tethera.net>  2021-02-25 07:59:39 -0400

WIP fixes for saving config path

not squashing yet because I have some simplification in mind
---
 lib/open.cc | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/lib/open.cc b/lib/open.cc
index 9edf0df3..2121c138 100644
--- a/lib/open.cc
+++ b/lib/open.cc
@@ -113,12 +113,12 @@ _choose_dir (notmuch_database_t *notmuch,
 }
 
 static notmuch_status_t
-_load_key_file (const char **config_path,
+_load_key_file (void *ctx,
+		const char **config_path,
 		const char *profile,
 		GKeyFile **key_file)
 {
     notmuch_status_t status = NOTMUCH_STATUS_SUCCESS;
-    void *local = talloc_new (NULL);
     const char *path = *config_path;
 
     if (path && EMPTY_STRING (path))
@@ -128,10 +128,10 @@ _load_key_file (const char **config_path,
 	path = getenv ("NOTMUCH_CONFIG");
 
     if (! path) {
-	const char *dir = _xdg_dir (local, "XDG_CONFIG_HOME", ".config", profile);
+	const char *dir = _xdg_dir (ctx, "XDG_CONFIG_HOME", ".config", profile);
 
 	if (dir) {
-	    path = talloc_asprintf (local, "%s/config", dir);
+	    path = talloc_asprintf (ctx, "%s/config", dir);
 	    if (access (path, R_OK) !=0)
 		path = NULL;
 	}
@@ -140,13 +140,13 @@ _load_key_file (const char **config_path,
     if (! path) {
 	const char *home = getenv ("HOME");
 
-	path = talloc_asprintf (local, "%s/.notmuch-config", home);
+	path = talloc_asprintf (ctx, "%s/.notmuch-config", home);
 
 	if (! profile)
 	    profile = getenv ("NOTMUCH_PROFILE");
 
 	if (profile)
-	    path = talloc_asprintf (local, "%s.%s", path, profile);
+	    path = talloc_asprintf (ctx, "%s.%s", path, profile);
     }
 
     *key_file = g_key_file_new ();
@@ -155,7 +155,6 @@ _load_key_file (const char **config_path,
     }
 
 DONE:
-    talloc_free (local);
     if (path)
 	*config_path = path;
 
@@ -478,7 +477,7 @@ notmuch_database_open_with_config (const char *database_path,
 	goto DONE;
     }
 
-    status =_load_key_file (&config_path, profile, &key_file);
+    status =_load_key_file (local, &config_path, profile, &key_file);
     if (status) {
 	message = strdup ("Error: cannot load config file.\n");
 	goto DONE;
@@ -571,7 +570,7 @@ notmuch_database_create_with_config (const char *database_path,
 	goto DONE;
     }
 
-    status =_load_key_file (&config_path, profile, &key_file);
+    status =_load_key_file (local, &config_path, profile, &key_file);
     if (status) {
 	message = strdup ("Error: cannot load config file.\n");
 	goto DONE;
@@ -758,9 +757,11 @@ notmuch_database_load_config (const char *database_path,
 	goto DONE;
     }
 
-    status =_load_key_file (&config_path, profile, &key_file);
+    status =_load_key_file (local, &config_path, profile, &key_file);
     switch (status) {
     case NOTMUCH_STATUS_SUCCESS:
+	notmuch->config_path = talloc_strdup (notmuch, config_path);
+	break;
     case NOTMUCH_STATUS_NO_CONFIG:
 	status2 = status;
 	break;


glossary
--------
Commit objects reference one tree, and zero or more parents.

Single parent commits can typically generate a patch in
unified diff format via `git format-patch'.

Multiple parents means the commit is a merge.

Root commits have no ancestor.  Note that it is
possible to have multiple root commits when merging independent histories.

Every commit references one top-level tree object.

git clone https://yhetil.org/notmuch.git