v5 merged config

Subject: v5 merged config

Date: Fri, 5 Feb 2021 09:26:15 -0400

To: notmuch@notmuchmail.org

Cc:

From: David Bremner


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],


_______________________________________________
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-leave@notmuchmail.org

Thread: