From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id IJWpDxO2xGAFLAAAgWs5BA (envelope-from ) for ; Sat, 12 Jun 2021 15:26:43 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id +LB4CxO2xGCfbQAA1q6Kng (envelope-from ) for ; Sat, 12 Jun 2021 13:26:43 +0000 Received: from mail.notmuchmail.org (nmbug.tethera.net [IPv6:2607:5300:201:3100::1657]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 81FB1244C6 for ; Sat, 12 Jun 2021 15:26:42 +0200 (CEST) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 66AA22B278; Sat, 12 Jun 2021 09:26:29 -0400 (EDT) Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197]) by mail.notmuchmail.org (Postfix) with ESMTP id E3D622B1E9 for ; Sat, 12 Jun 2021 09:26:23 -0400 (EDT) Received: by fethera.tethera.net (Postfix, from userid 1001) id 64E895FD26; Sat, 12 Jun 2021 09:26:23 -0400 (EDT) Received: (nullmailer pid 813251 invoked by uid 1000); Sat, 12 Jun 2021 13:26:20 -0000 From: David Bremner To: notmuch@notmuchmail.org Cc: David Bremner Subject: [PATCH 2/2] CLI: move indexopts variable out of shared options block Date: Sat, 12 Jun 2021 10:26:17 -0300 Message-Id: <20210612132617.813170-3-david@tethera.net> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210612132617.813170-1-david@tethera.net> References: <20210612132617.813170-1-david@tethera.net> MIME-Version: 1.0 Message-ID-Hash: GVOCB4ZZZ3HV7XNCEC2H3Z6WS4D7HVXL X-Message-ID-Hash: GVOCB4ZZZ3HV7XNCEC2H3Z6WS4D7HVXL X-MailFrom: bremner@tethera.net X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-notmuch.notmuchmail.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.1 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1623504402; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=rhDdUciGV5wrRelNBq5Mzp9JrQ2QRyB5Em8aD4JGyG0=; b=MFoOzldxL9Ar8JlM1o8R0e7FhzZAI6pjzZ/0gClKt4B97hqRUiWJifbjkr3POhOzqR3Vfp o9vKjwhO7IkeGFrIO3BwPBfZxeVQ859yNFdI5IzaQ2rSKOn4mSr56JFEOKOz0sakx3ieGu 1nWsCrwgSoEvwoGDqYyCVGenNFLZnooOHpFB7vr6DatOJymzATDSVtrAa8ldGKdvxsw1aP p+PDfAHqaRCM1YZe91ioWQqFJdx5Dw0qaSKGlMRDlrYD4rPwj21cL1jYszhEV91nN3+FSv OhmGYvyIuL+xbWU7cYqWY8qTS5exnvJWdB9ON4G+Ghk4DM6XFRVGAzoDGs4JvA== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1623504402; a=rsa-sha256; cv=none; b=IjpxNIb+0QyxqoLo95GF8+O0sd0gnNpM2aWWTCqO/ph6mZzxnIQDB5mIaXvmN5Lo8KRgS1 ClmtClN0fmQHK17nBTAa09ADNhV7gl3uS8W+RwWzEptBgQjj/MjzbXVgm4H6gqemNdvecz FiRkJf3TOzA4h0vBIrRT1lyCUsd/z82LhWTSwWLxO1WJyzGOhTLni4lBN4bNKJ3Md5h7Tn nhS59w5n58EkFGca90jsgiBsPHc7OYLoZJOoI5seXkyt9WjWzjL9e4NQ2ZI9zANiA2uJEz FchAqd9RUx36/n8arjnR+TijhfNCJ3jv4EucRMc5Di87s8gT28BeiqVxLhJvLg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 2607:5300:201:3100::1657 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Spam-Score: -1.04 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 2607:5300:201:3100::1657 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Queue-Id: 81FB1244C6 X-Spam-Score: -1.04 X-Migadu-Scanner: scn0.migadu.com X-TUID: DV2GFnnWp42t 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