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 ms11 with LMTPS id Vf93OCG0Ll/SCQAA0tVLHw (envelope-from ) for ; Sat, 08 Aug 2020 14:18:09 +0000 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 8Km0MyG0Ll/pZQAA1q6Kng (envelope-from ) for ; Sat, 08 Aug 2020 14:18:09 +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) server-signature RSA-PSS (2048 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 494FD940983 for ; Sat, 8 Aug 2020 14:18:06 +0000 (UTC) Received: from [144.217.243.247] (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id C319629B22; Sat, 8 Aug 2020 10:17:36 -0400 (EDT) Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197]) by mail.notmuchmail.org (Postfix) with ESMTP id 09C1429AE9 for ; Sat, 8 Aug 2020 10:17:17 -0400 (EDT) Received: by fethera.tethera.net (Postfix, from userid 1001) id 0477E5FA66; Sat, 8 Aug 2020 10:17:16 -0400 (EDT) Received: (nullmailer pid 1124294 invoked by uid 1000); Sat, 08 Aug 2020 14:17:04 -0000 From: David Bremner To: notmuch@notmuchmail.org Cc: David Bremner Subject: [PATCH 18/19] WIP converting notmuch search to new style config Date: Sat, 8 Aug 2020 11:16:52 -0300 Message-Id: <20200808141653.1124111-19-david@tethera.net> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200808141653.1124111-1-david@tethera.net> References: <20200808141653.1124111-1-david@tethera.net> MIME-Version: 1.0 Message-ID-Hash: YEAQBTBRHTGJYJ242RHBGUHFLHXW5HNK X-Message-ID-Hash: YEAQBTBRHTGJYJ242RHBGUHFLHXW5HNK 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-Scanner: scn0 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-Spam-Score: 0.03 X-TUID: 4nWgpbCfHbxy this breaks passing the config file as a command line argument, but that is not currently tested for notmuch-search --- notmuch-search.c | 45 +++++++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/notmuch-search.c b/notmuch-search.c index 2805d960..4a5a57c9 100644 --- a/notmuch-search.c +++ b/notmuch-search.c @@ -52,6 +52,7 @@ typedef enum { typedef struct { notmuch_database_t *notmuch; + void *talloc_ctx; int format_sel; sprinter_t *format; int exclude; @@ -677,28 +678,32 @@ do_search_tags (const search_context_t *ctx) } static int -_notmuch_search_prepare (search_context_t *ctx, notmuch_config_t *config, int argc, char *argv[]) +_notmuch_search_prepare (search_context_t *ctx, + const char *config_path, + int argc, char *argv[]) { char *query_str; - unsigned int i; char *status_string = NULL; + if (! ctx->talloc_ctx) + ctx->talloc_ctx = talloc_new (NULL); + switch (ctx->format_sel) { case NOTMUCH_FORMAT_TEXT: - ctx->format = sprinter_text_create (config, stdout); + ctx->format = sprinter_text_create (ctx->talloc_ctx, stdout); break; case NOTMUCH_FORMAT_TEXT0: if (ctx->output == OUTPUT_SUMMARY) { fprintf (stderr, "Error: --format=text0 is not compatible with --output=summary.\n"); return EXIT_FAILURE; } - ctx->format = sprinter_text0_create (config, stdout); + ctx->format = sprinter_text0_create (ctx->talloc_ctx, stdout); break; case NOTMUCH_FORMAT_JSON: - ctx->format = sprinter_json_create (config, stdout); + ctx->format = sprinter_json_create (ctx->talloc_ctx, stdout); break; case NOTMUCH_FORMAT_SEXP: - ctx->format = sprinter_sexp_create (config, stdout); + ctx->format = sprinter_sexp_create (ctx->talloc_ctx, stdout); break; default: /* this should never happen */ @@ -707,9 +712,12 @@ _notmuch_search_prepare (search_context_t *ctx, notmuch_config_t *config, int ar notmuch_exit_if_unsupported_format (); - if (notmuch_database_open_verbose ( - notmuch_config_get_database_path (config), - NOTMUCH_DATABASE_MODE_READ_ONLY, &ctx->notmuch, &status_string)) { + if (notmuch_database_open_with_config ( + NULL, + NOTMUCH_DATABASE_MODE_READ_ONLY, + config_path, + NULL, + &ctx->notmuch, &status_string)) { if (status_string) { fputs (status_string, stderr); @@ -748,21 +756,20 @@ _notmuch_search_prepare (search_context_t *ctx, notmuch_config_t *config, int ar } if (ctx->exclude != NOTMUCH_EXCLUDE_FALSE) { - const char **search_exclude_tags; - size_t search_exclude_tags_length; + notmuch_config_values_t *exclude_tags; notmuch_status_t status; - search_exclude_tags = notmuch_config_get_search_exclude_tags ( - config, &search_exclude_tags_length); + for (exclude_tags = notmuch_config_get_values (ctx->notmuch, "search.exclude_tags"); + notmuch_config_values_valid (exclude_tags); + notmuch_config_values_move_to_next (exclude_tags)) { - for (i = 0; i < search_exclude_tags_length; i++) { - status = notmuch_query_add_tag_exclude (ctx->query, search_exclude_tags[i]); + status = notmuch_query_add_tag_exclude (ctx->query, + notmuch_config_values_get (exclude_tags)); if (status && status != NOTMUCH_STATUS_IGNORED) { print_status_query ("notmuch search", ctx->query, status); return EXIT_FAILURE; } } - notmuch_query_set_omit_excluded (ctx->query, ctx->exclude); } @@ -845,7 +852,8 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[]) return EXIT_FAILURE; } - if (_notmuch_search_prepare (ctx, config, + if (_notmuch_search_prepare (ctx, + _notmuch_config_get_path (config), argc - opt_index, argv + opt_index)) return EXIT_FAILURE; @@ -911,7 +919,8 @@ notmuch_address_command (notmuch_config_t *config, int argc, char *argv[]) return EXIT_FAILURE; } - if (_notmuch_search_prepare (ctx, config, + if (_notmuch_search_prepare (ctx, + _notmuch_config_get_path (config), argc - opt_index, argv + opt_index)) return EXIT_FAILURE; -- 2.28.0