unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: David Bremner <david@tethera.net>
To: notmuch@notmuchmail.org
Subject: v5 merged config
Date: Fri,  5 Feb 2021 09:26:15 -0400	[thread overview]
Message-ID: <20210205132654.3258292-1-david@tethera.net> (raw)

The main difference since Tomi's review is that I made several more
tests for configuration path searching in T035-read-config.sh, and
moved some of the existing ones there.

The other diffs are as follows. The update of the private status
values is partially cleanup, it includes the codes added by this
series, but also others missed. I have to confess that I have not
really been using the private status values in new code.

diff --git a/lib/config.cc b/lib/config.cc
index 4b115a07..948751bc 100644
--- a/lib/config.cc
+++ b/lib/config.cc
@@ -330,7 +330,7 @@ _notmuch_config_load_from_file (notmuch_database_t *notmuch,
 				GKeyFile *file)
 {
     notmuch_status_t status = NOTMUCH_STATUS_SUCCESS;
-    gchar **groups,**keys, *val;
+    gchar **groups, **keys, *val;
 
     if (notmuch->config == NULL)
 	notmuch->config = _notmuch_string_map_create (notmuch);
diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h
index 5e0b42e3..2fbf7ab9 100644
--- a/lib/notmuch-private.h
+++ b/lib/notmuch-private.h
@@ -129,10 +129,22 @@ typedef enum _notmuch_private_status {
     NOTMUCH_PRIVATE_STATUS_OUT_OF_MEMORY		= NOTMUCH_STATUS_OUT_OF_MEMORY,
     NOTMUCH_PRIVATE_STATUS_READ_ONLY_DATABASE		= NOTMUCH_STATUS_READ_ONLY_DATABASE,
     NOTMUCH_PRIVATE_STATUS_XAPIAN_EXCEPTION		= NOTMUCH_STATUS_XAPIAN_EXCEPTION,
+    NOTMUCH_PRIVATE_STATUS_FILE_ERROR			= NOTMUCH_STATUS_FILE_ERROR,
     NOTMUCH_PRIVATE_STATUS_FILE_NOT_EMAIL		= NOTMUCH_STATUS_FILE_NOT_EMAIL,
     NOTMUCH_PRIVATE_STATUS_NULL_POINTER			= NOTMUCH_STATUS_NULL_POINTER,
     NOTMUCH_PRIVATE_STATUS_TAG_TOO_LONG			= NOTMUCH_STATUS_TAG_TOO_LONG,
     NOTMUCH_PRIVATE_STATUS_UNBALANCED_FREEZE_THAW	= NOTMUCH_STATUS_UNBALANCED_FREEZE_THAW,
+    NOTMUCH_PRIVATE_STATUS_UNBALANCED_ATOMIC		= NOTMUCH_STATUS_UNBALANCED_ATOMIC,
+    NOTMUCH_PRIVATE_STATUS_UNSUPPORTED_OPERATION	= NOTMUCH_STATUS_UNSUPPORTED_OPERATION,
+    NOTMUCH_PRIVATE_STATUS_UPGRADE_REQUIRED		= NOTMUCH_STATUS_UPGRADE_REQUIRED,
+    NOTMUCH_PRIVATE_STATUS_PATH_ERROR			= NOTMUCH_STATUS_PATH_ERROR,
+    NOTMUCH_PRIVATE_STATUS_IGNORED			= NOTMUCH_STATUS_IGNORED,
+    NOTMUCH_PRIVATE_STATUS_ILLEGAL_ARGUMENT		= NOTMUCH_STATUS_ILLEGAL_ARGUMENT,
+    NOTMUCH_PRIVATE_STATUS_MALFORMED_CRYPTO_PROTOCOL		= NOTMUCH_STATUS_MALFORMED_CRYPTO_PROTOCOL,
+    NOTMUCH_PRIVATE_STATUS_FAILED_CRYPTO_CONTEXT_CREATION	= NOTMUCH_STATUS_FAILED_CRYPTO_CONTEXT_CREATION,
+    NOTMUCH_PRIVATE_STATUS_UNKNOWN_CRYPTO_PROTOCOL		= NOTMUCH_STATUS_UNKNOWN_CRYPTO_PROTOCOL,
+    NOTMUCH_PRIVATE_STATUS_NO_CONFIG				= NOTMUCH_STATUS_NO_CONFIG,
+    NOTMUCH_PRIVATE_STATUS_DATABASE_EXISTS			= NOTMUCH_STATUS_DATABASE_EXISTS,
 
     /* Then add our own private values. */
     NOTMUCH_PRIVATE_STATUS_TERM_TOO_LONG		= NOTMUCH_STATUS_LAST_STATUS,
diff --git a/lib/notmuch.h b/lib/notmuch.h
index 3c3fd487..5a5d99c0 100644
--- a/lib/notmuch.h
+++ b/lib/notmuch.h
@@ -446,13 +446,12 @@ notmuch_database_open_with_config (const char *database_path,
  * Create a new notmuch database located at 'database_path', using
  * configuration in 'config_path'.
  *
- * @param[in,out] is_new if NULL consider an existing database as an
- *		  error.  Otherwise report whether actually created.
- *
- * For description of other arguments, see notmuch_database_open_with_config
+ * For description of arguments, @see notmuch_database_open_with_config
  *
  * @retval NOTMUCH_STATUS_SUCCESS: Successfully created the database.
  *
+ * @retval NOTMUCH_STATUS_DATABASE_EXISTS: Database already exists, not created
+ *
  * @retval NOTMUCH_STATUS_OUT_OF_MEMORY: Out of memory.
  *
  * @retval NOTMUCH_STATUS_FILE_ERROR: An error occurred trying to open the
diff --git a/lib/open.cc b/lib/open.cc
index eb7c8a01..b4637ec5 100644
--- a/lib/open.cc
+++ b/lib/open.cc
@@ -44,9 +44,10 @@ _xdg_dir (void *ctx,
 	  const char *profile_name)
 {
     const char *xdg_root = getenv (xdg_root_variable);
-    const char *home = getenv ("HOME");
 
     if (! xdg_root) {
+	const char *home = getenv ("HOME");
+
 	if (! home) return NULL;
 
 	xdg_root = talloc_asprintf (ctx,
@@ -152,11 +153,11 @@ DONE:
 }
 
 static notmuch_status_t
-_pre_open(const char *config_path,
-	  const char *profile,
-	  GKeyFile **key_file,
-	  const char **database_path,
-	  char **message)
+_choose_database_path (const char *config_path,
+		       const char *profile,
+		       GKeyFile **key_file,
+		       const char **database_path,
+		       char **message)
 {
     notmuch_status_t status;
 
@@ -200,7 +201,7 @@ notmuch_database_open_with_config (const char *database_path,
     GKeyFile *key_file = NULL;
     static int initialized = 0;
 
-    if ((status = _pre_open (config_path, profile, &key_file, &database_path, &message)))
+    if ((status = _choose_database_path (config_path, profile, &key_file, &database_path, &message)))
 	goto DONE;
 
     if (! (notmuch_path = talloc_asprintf (local, "%s/%s", database_path, ".notmuch"))) {
@@ -423,7 +424,7 @@ notmuch_database_create_with_config (const char *database_path,
     struct stat st;
     int err;
 
-    if ((status = _pre_open (config_path, profile, &key_file, &database_path, &message)))
+    if ((status = _choose_database_path (config_path, profile, &key_file, &database_path, &message)))
 	goto DONE;
 
     err = stat (database_path, &st);
diff --git a/lib/string-map.c b/lib/string-map.c
index 1f3215fb..71eac634 100644
--- a/lib/string-map.c
+++ b/lib/string-map.c
@@ -142,8 +142,11 @@ bsearch_first (notmuch_string_pair_t *array, size_t len, const char *key, bool e
 	return NULL;
 
 }
+
 void
-_notmuch_string_map_set (notmuch_string_map_t *map, const char *key, const char *val)
+_notmuch_string_map_set (notmuch_string_map_t *map,
+			 const char *key,
+			 const char *val)
 {
     notmuch_string_pair_t *pair;
 
diff --git a/notmuch-new.c b/notmuch-new.c
index 2fc34e2c..21e66af1 100644
--- a/notmuch-new.c
+++ b/notmuch-new.c
@@ -1105,7 +1105,6 @@ notmuch_new_command (unused(notmuch_config_t *config), notmuch_database_t *notmu
     struct timeval tv_start;
     int ret = 0;
     const char *db_path;
-    char *dot_notmuch_path;
     struct sigaction action;
     _filename_node_t *f;
     int opt_index;
@@ -1172,8 +1171,6 @@ notmuch_new_command (unused(notmuch_config_t *config), notmuch_database_t *notmu
 	    return EXIT_FAILURE;
     }
 
-    dot_notmuch_path = talloc_asprintf (notmuch, "%s/%s", db_path, ".notmuch");
-
     notmuch_exit_if_unmatched_db_uuid (notmuch);
 
     if (notmuch_database_get_revision (notmuch, NULL) == 0) {
@@ -1212,9 +1209,6 @@ notmuch_new_command (unused(notmuch_config_t *config), notmuch_database_t *notmu
     action.sa_flags = SA_RESTART;
     sigaction (SIGINT, &action, NULL);
 
-    talloc_free (dot_notmuch_path);
-    dot_notmuch_path = NULL;
-
     gettimeofday (&add_files_state.tv_start, NULL);
 
     add_files_state.removed_files = _filename_list_create (notmuch);
diff --git a/test/T400-hooks.sh b/test/T400-hooks.sh
index b9894853..a3dd4c63 100755
--- a/test/T400-hooks.sh
+++ b/test/T400-hooks.sh
@@ -47,7 +47,7 @@ for config in traditional profile explicit XDG; do
 	    mkdir -p $HOOK_DIR
 	    notmuch config set database.hook_dir $HOOK_DIR
 	    ;;
-	*)
+	XDG)
 	    HOOK_DIR=${HOME}/.config/notmuch/default/hooks
 	    ;;
     esac
diff --git a/test/T590-libconfig.sh b/test/T590-libconfig.sh
index c78ed204..e7e6e08a 100755
--- a/test/T590-libconfig.sh
+++ b/test/T590-libconfig.sh
@@ -17,7 +17,7 @@ int main (int argc, char** argv)
    notmuch_status_t stat;
    char *msg = NULL;
 
-   for (int i=1; i<argc; i++)
+   for (int i = 1; i < argc; i++)
       if (strcmp (argv[i], "%NULL%") == 0) argv[i] = NULL;
 
    stat = notmuch_database_open_with_config (argv[1],


             reply	other threads:[~2021-02-05 13:27 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-05 13:26 David Bremner [this message]
2021-02-05 13:26 ` [PATCH 01/39] lib: add _notmuch_string_map_set David Bremner
2021-02-05 13:26 ` [PATCH 02/39] lib: cache configuration information from database David Bremner
2021-02-05 13:26 ` [PATCH 03/39] lib: add stub for notmuch_database_open_with_config David Bremner
2021-02-05 13:26 ` [PATCH 04/39] lib/open: add support for config profiles and default locations David Bremner
2021-02-05 13:26 ` [PATCH 05/39] CLI: generalize notmuch_config_mode_t David Bremner
2021-02-05 13:26 ` [PATCH 06/39] lib/config: add notmuch_config_key_{get,set} David Bremner
2021-02-05 13:26 ` [PATCH 07/39] lib/open: load default values for known configuration keys David Bremner
2021-02-05 13:26 ` [PATCH 08/39] CLI: add (unused) database argument to subcommands David Bremner
2021-02-05 13:26 ` [PATCH 09/39] util: add strsplit_len: simplified strtok with delimiter escaping David Bremner
2021-02-05 13:26 ` [PATCH 10/39] lib/config: add config values iterator David Bremner
2021-02-05 13:26 ` [PATCH 11/39] lib/config: make values iterators restartable David Bremner
2021-02-05 13:26 ` [PATCH 12/39] CLI/count: switch to new configuration framework David Bremner
2021-02-05 13:26 ` [PATCH 13/39] cli/dump: convert to new config framework David Bremner
2021-02-05 13:26 ` [PATCH 14/39] lib: add notmuch_config_get_bool David Bremner
2021-02-05 13:26 ` [PATCH 15/39] CLI/restore: convert to new config framework David Bremner
2021-02-05 13:26 ` [PATCH 16/39] CLI/insert: " David Bremner
2021-02-05 13:26 ` [PATCH 17/39] cli/reindex: convert " David Bremner
2021-02-05 13:26 ` [PATCH 18/39] CLI/reply: convert to " David Bremner
2021-02-05 13:26 ` [PATCH 19/39] CLI/{search,address}: convert to new configuration framework David Bremner
2021-02-05 13:26 ` [PATCH 20/39] cli/config: add accessor for config file name David Bremner
2021-02-05 13:26 ` [PATCH 21/39] CLI/show: mostly switch show to new config framework David Bremner
2021-02-06 19:21   ` [PATCH] " David Bremner
2021-02-05 13:26 ` [PATCH 22/39] cli/tag: convert " David Bremner
2021-02-05 13:26 ` [PATCH 23/39] lib/config: add _notmuch_config_cache David Bremner
2021-02-05 13:26 ` [PATCH 24/39] lib: split notmuch_database_compact David Bremner
2021-02-05 13:26 ` [PATCH 25/39] cli/compact: convert to new configuration framework David Bremner
2021-02-05 13:26 ` [PATCH 26/39] bindings/notmuch2: add missing crypto error status codes David Bremner
2021-02-05 13:26 ` [PATCH 27/39] lib/config: add NOTMUCH_CONFIG_NEW_IGNORE David Bremner
2021-02-05 13:26 ` [PATCH 28/39] lib/open: factor out choosing database path David Bremner
2021-02-05 13:26 ` [PATCH 29/39] lib: add NOTMUCH_STATUS_NO_CONFIG David Bremner
2021-02-05 13:26 ` [PATCH 30/39] lib/database: move n_d_create* to open.cc David Bremner
2021-02-05 13:26 ` [PATCH 31/39] lib: add NOTMUCH_STATUS_DATABASE_EXISTS David Bremner
2021-02-05 13:26 ` [PATCH 32/39] lib: introduce notmuch_database_create_with_config David Bremner
2021-02-05 13:26 ` [PATCH 33/39] cli/new: refactor database upgrade code David Bremner
2021-02-05 13:26 ` [PATCH 34/39] cli/new: convert to new config framework David Bremner
2021-02-05 13:26 ` [PATCH 35/39] lib/config: add HOOK_DIR David Bremner
2021-02-05 13:26 ` [PATCH 36/39] lib/open: set HOOK_DIR on open David Bremner
2021-02-05 13:26 ` [PATCH 37/39] CLI: use configured hook directory David Bremner
2021-02-05 13:26 ` [PATCH 38/39] doc: describe new config framework David Bremner
2021-02-05 13:26 ` [PATCH 39/39] lib: add missing private status values David Bremner
2021-02-07  0:19   ` Complete conversion of notmuch-show to new config framework David Bremner
2021-02-07  0:19     ` [PATCH 1/4] lib: publish API for notmuch_database_reopen David Bremner
2021-02-07  0:19     ` [PATCH 2/4] lib: save path of xapian database in notmuch struct David Bremner
2021-02-07  0:19     ` [PATCH 3/4] lib: support reopening databases for write access David Bremner
2021-02-07  0:19     ` [PATCH 4/4] CLI/show: complete conversion to new configuration framework David Bremner
2021-02-07  1:02 ` v5 merged config 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=20210205132654.3258292-1-david@tethera.net \
    --to=david@tethera.net \
    --cc=notmuch@notmuchmail.org \
    --subject='Re: v5 merged config' \
    /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

Code repositories for project(s) associated with this inbox:

	notmuch.git.git (no URL configured)

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).