unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: David Bremner <david@tethera.net>
To: notmuch@notmuchmail.org
Cc: David Bremner <david@tethera.net>
Subject: [PATCH 2/2] CLI: move indexopts variable out of shared options block
Date: Sat, 12 Jun 2021 10:26:17 -0300	[thread overview]
Message-ID: <20210612132617.813170-3-david@tethera.net> (raw)
In-Reply-To: <20210612132617.813170-1-david@tethera.net>

This reduces the amount of global state.  Furthermore, index options
can be set (in principle) in several ways, not just in the one
function for processing indexing command line options.
---
 notmuch-client.h  |  3 +--
 notmuch-insert.c  |  6 ++++--
 notmuch-new.c     |  7 +++++--
 notmuch-reindex.c |  5 +++--
 notmuch.c         | 13 +++++--------
 5 files changed, 18 insertions(+), 16 deletions(-)

diff --git a/notmuch-client.h b/notmuch-client.h
index 8227fea4..6abe3ea5 100644
--- a/notmuch-client.h
+++ b/notmuch-client.h
@@ -499,11 +499,10 @@ int notmuch_minimal_options (const char *subcommand_name,
 struct _notmuch_client_indexing_cli_choices {
     int decrypt_policy;
     bool decrypt_policy_set;
-    notmuch_indexopts_t *opts;
 };
 extern struct _notmuch_client_indexing_cli_choices indexing_cli_choices;
 extern const notmuch_opt_desc_t notmuch_shared_indexing_options [];
 notmuch_status_t
-notmuch_process_shared_indexing_options (notmuch_database_t *notmuch);
+notmuch_process_shared_indexing_options (notmuch_indexopts_t *opts);
 
 #endif
diff --git a/notmuch-insert.c b/notmuch-insert.c
index e3d87e4a..beeefe12 100644
--- a/notmuch-insert.c
+++ b/notmuch-insert.c
@@ -461,6 +461,8 @@ notmuch_insert_command (notmuch_database_t *notmuch, int argc, char *argv[])
     char *maildir;
     char *newpath;
     int opt_index;
+    notmuch_indexopts_t *indexopts = notmuch_database_get_default_indexopts (notmuch);
+
     void *local = talloc_new (NULL);
 
     notmuch_opt_desc_t options[] = {
@@ -552,7 +554,7 @@ notmuch_insert_command (notmuch_database_t *notmuch, int argc, char *argv[])
 
     notmuch_exit_if_unmatched_db_uuid (notmuch);
 
-    status = notmuch_process_shared_indexing_options (notmuch);
+    status = notmuch_process_shared_indexing_options (indexopts);
     if (status != NOTMUCH_STATUS_SUCCESS) {
 	fprintf (stderr, "Error: Failed to process index options. (%s)\n",
 		 notmuch_status_to_string (status));
@@ -560,7 +562,7 @@ notmuch_insert_command (notmuch_database_t *notmuch, int argc, char *argv[])
     }
 
     /* Index the message. */
-    status = add_file (notmuch, newpath, tag_ops, synchronize_flags, keep, indexing_cli_choices.opts);
+    status = add_file (notmuch, newpath, tag_ops, synchronize_flags, keep, indexopts);
 
     /* Commit changes. */
     close_status = notmuch_database_close (notmuch);
diff --git a/notmuch-new.c b/notmuch-new.c
index 1ee498fa..1fb22c1f 100644
--- a/notmuch-new.c
+++ b/notmuch-new.c
@@ -45,6 +45,7 @@ typedef struct {
     const char *db_path;
     const char *mail_root;
 
+    notmuch_indexopts_t *indexopts;
     int output_is_a_tty;
     enum verbosity verbosity;
     bool debug;
@@ -376,7 +377,7 @@ add_file (notmuch_database_t *notmuch, const char *filename,
     if (status)
 	goto DONE;
 
-    status = notmuch_database_index_file (notmuch, filename, indexing_cli_choices.opts, &message);
+    status = notmuch_database_index_file (notmuch, filename, state->indexopts, &message);
     switch (status) {
     /* Success. */
     case NOTMUCH_STATUS_SUCCESS:
@@ -1150,6 +1151,8 @@ notmuch_new_command (notmuch_database_t *notmuch, int argc, char *argv[])
     else if (verbose)
 	add_files_state.verbosity = VERBOSITY_VERBOSE;
 
+    add_files_state.indexopts = notmuch_database_get_default_indexopts (notmuch);
+
     add_files_state.new_tags = notmuch_config_get_values (notmuch, NOTMUCH_CONFIG_NEW_TAGS);
 
     if (print_status_database (
@@ -1219,7 +1222,7 @@ notmuch_new_command (notmuch_database_t *notmuch, int argc, char *argv[])
     if (notmuch == NULL)
 	return EXIT_FAILURE;
 
-    status = notmuch_process_shared_indexing_options (notmuch);
+    status = notmuch_process_shared_indexing_options (add_files_state.indexopts);
     if (status != NOTMUCH_STATUS_SUCCESS) {
 	fprintf (stderr, "Error: Failed to process index options. (%s)\n",
 		 notmuch_status_to_string (status));
diff --git a/notmuch-reindex.c b/notmuch-reindex.c
index a7380a4b..0d957959 100644
--- a/notmuch-reindex.c
+++ b/notmuch-reindex.c
@@ -90,6 +90,7 @@ notmuch_reindex_command (notmuch_database_t *notmuch, int argc, char *argv[])
     int opt_index;
     int ret;
     notmuch_status_t status;
+    notmuch_indexopts_t *indexopts = notmuch_database_get_default_indexopts (notmuch);
 
     /* Set up our handler for SIGINT */
     memset (&action, 0, sizeof (struct sigaction));
@@ -112,7 +113,7 @@ notmuch_reindex_command (notmuch_database_t *notmuch, int argc, char *argv[])
 
     notmuch_exit_if_unmatched_db_uuid (notmuch);
 
-    status = notmuch_process_shared_indexing_options (notmuch);
+    status = notmuch_process_shared_indexing_options (indexopts);
     if (status != NOTMUCH_STATUS_SUCCESS) {
 	fprintf (stderr, "Error: Failed to process index options. (%s)\n",
 		 notmuch_status_to_string (status));
@@ -130,7 +131,7 @@ notmuch_reindex_command (notmuch_database_t *notmuch, int argc, char *argv[])
 	return EXIT_FAILURE;
     }
 
-    ret = reindex_query (notmuch, query_string, indexing_cli_choices.opts);
+    ret = reindex_query (notmuch, query_string, indexopts);
 
     notmuch_database_destroy (notmuch);
 
diff --git a/notmuch.c b/notmuch.c
index d0a94fc2..a0f35e13 100644
--- a/notmuch.c
+++ b/notmuch.c
@@ -117,21 +117,18 @@ const notmuch_opt_desc_t notmuch_shared_indexing_options [] = {
 
 
 notmuch_status_t
-notmuch_process_shared_indexing_options (notmuch_database_t *notmuch)
+notmuch_process_shared_indexing_options (notmuch_indexopts_t *opts)
 {
-    if (indexing_cli_choices.opts == NULL)
-	indexing_cli_choices.opts = notmuch_database_get_default_indexopts (notmuch);
+    if (opts == NULL)
+	return NOTMUCH_STATUS_NULL_POINTER;
+
     if (indexing_cli_choices.decrypt_policy_set) {
 	notmuch_status_t status;
-	if (indexing_cli_choices.opts == NULL)
-	    return NOTMUCH_STATUS_OUT_OF_MEMORY;
-	status = notmuch_indexopts_set_decrypt_policy (indexing_cli_choices.opts,
+	status = notmuch_indexopts_set_decrypt_policy (opts,
 						       indexing_cli_choices.decrypt_policy);
 	if (status != NOTMUCH_STATUS_SUCCESS) {
 	    fprintf (stderr, "Error: Failed to set index decryption policy to %d. (%s)\n",
 		     indexing_cli_choices.decrypt_policy, notmuch_status_to_string (status));
-	    notmuch_indexopts_destroy (indexing_cli_choices.opts);
-	    indexing_cli_choices.opts = NULL;
 	    return status;
 	}
     }
-- 
2.30.2

  parent reply	other threads:[~2021-06-12 13:26 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-12 13:26 indexopts cleanup David Bremner
2021-06-12 13:26 ` [PATCH 1/2] lib: make indexopts pointers opaque David Bremner
2021-06-12 13:26 ` David Bremner [this message]
2021-10-23 12:56   ` [PATCH 2/2] CLI: move indexopts variable out of shared options block 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=20210612132617.813170-3-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).