From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by arlo.cworth.org (Postfix) with ESMTP id 4378D6DE12C1 for ; Mon, 5 Sep 2016 08:48:22 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: -0.007 X-Spam-Level: X-Spam-Status: No, score=-0.007 tagged_above=-999 required=5 tests=[AWL=0.004, SPF_PASS=-0.001, T_RP_MATCHES_RCVD=-0.01] autolearn=disabled Received: from arlo.cworth.org ([127.0.0.1]) by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id yZ8DNbXnOW1Q for ; Mon, 5 Sep 2016 08:48:21 -0700 (PDT) Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197]) by arlo.cworth.org (Postfix) with ESMTPS id 9BCA86DE12D9 for ; Mon, 5 Sep 2016 08:48:18 -0700 (PDT) Received: from remotemail by fethera.tethera.net with local (Exim 4.84_2) (envelope-from ) id 1bgw84-0001cg-RI; Mon, 05 Sep 2016 11:48:12 -0400 Received: (nullmailer pid 24449 invoked by uid 1000); Mon, 05 Sep 2016 15:48:12 -0000 From: David Bremner To: notmuch@notmuchmail.org Subject: [PATCH 5/5] lib: make notmuch_query_add_tag_exclude return a status value Date: Mon, 5 Sep 2016 12:48:06 -0300 Message-Id: <20160905154806.4570-6-david@tethera.net> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20160905154806.4570-1-david@tethera.net> References: <20160905154806.4570-1-david@tethera.net> X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 05 Sep 2016 15:48:22 -0000 Since this is an ABI breaking change, bump the SONAME. --- lib/notmuch.h | 19 +++++++++++++++++-- lib/query.cc | 7 ++++--- notmuch-count.c | 9 +++++++-- notmuch-search.c | 12 ++++++++++-- notmuch-show.c | 13 +++++++++++-- 5 files changed, 49 insertions(+), 11 deletions(-) diff --git a/lib/notmuch.h b/lib/notmuch.h index 2faa146..2396aa1 100644 --- a/lib/notmuch.h +++ b/lib/notmuch.h @@ -180,6 +180,11 @@ typedef enum _notmuch_status { */ NOTMUCH_STATUS_PATH_ERROR, /** + * The requested operation was ignored. Depending on the function, + * this may not be an actual error. + */ + NOTMUCH_STATUS_IGNORED, + /** * Not an actual status value. Just a way to find out how many * valid status values there are. */ @@ -807,10 +812,20 @@ notmuch_query_get_sort (const notmuch_query_t *query); /** * Add a tag that will be excluded from the query results by default. - * This exclusion will be overridden if this tag appears explicitly in + * This exclusion will be ignored if this tag appears explicitly in * the query. + * + * @returns + * + * NOTMUCH_STATUS_SUCCESS: excluded was added successfully. + * + * NOTMUCH_STATUS_XAPIAN_EXCEPTION: a Xapian exception occured. + * Most likely a problem lazily parsing the query string. + * + * NOTMUCH_STATUS_IGNORED: tag is explicitely present in the query, so + * not excluded. */ -void +notmuch_status_t notmuch_query_add_tag_exclude (notmuch_query_t *query, const char *tag); /** diff --git a/lib/query.cc b/lib/query.cc index 81e3e01..2918543 100644 --- a/lib/query.cc +++ b/lib/query.cc @@ -170,7 +170,7 @@ notmuch_query_get_sort (const notmuch_query_t *query) return query->sort; } -void +notmuch_status_t notmuch_query_add_tag_exclude (notmuch_query_t *query, const char *tag) { notmuch_status_t status; @@ -178,13 +178,14 @@ notmuch_query_add_tag_exclude (notmuch_query_t *query, const char *tag) status = _notmuch_query_ensure_parsed (query); if (status) - return; /* XXX report error */ + return status; term = talloc_asprintf (query, "%s%s", _find_prefix ("tag"), tag); if (query->terms.count(term) != 0) - return; /* XXX report ignoring exclude? */ + return NOTMUCH_STATUS_IGNORED; _notmuch_string_list_append (query->exclude_terms, term); + return NOTMUCH_STATUS_SUCCESS; } /* We end up having to call the destructors explicitly because we had diff --git a/notmuch-count.c b/notmuch-count.c index 35a2aa7..3207c01 100644 --- a/notmuch-count.c +++ b/notmuch-count.c @@ -87,8 +87,13 @@ print_count (notmuch_database_t *notmuch, const char *query_str, return -1; } - for (i = 0; i < exclude_tags_length; i++) - notmuch_query_add_tag_exclude (query, exclude_tags[i]); + for (i = 0; i < exclude_tags_length; i++) { + status = notmuch_query_add_tag_exclude (query, exclude_tags[i]); + if (status && status != NOTMUCH_STATUS_IGNORED) { + print_status_query ("notmuch count", query, status); + return -1; + } + } switch (output) { case OUTPUT_MESSAGES: diff --git a/notmuch-search.c b/notmuch-search.c index 8c65d5a..64a9811 100644 --- a/notmuch-search.c +++ b/notmuch-search.c @@ -735,11 +735,19 @@ _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_status_t status; search_exclude_tags = notmuch_config_get_search_exclude_tags (config, &search_exclude_tags_length); - for (i = 0; i < search_exclude_tags_length; i++) - notmuch_query_add_tag_exclude (ctx->query, search_exclude_tags[i]); + + for (i = 0; i < search_exclude_tags_length; i++) { + status = notmuch_query_add_tag_exclude (ctx->query, search_exclude_tags[i]); + 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); } diff --git a/notmuch-show.c b/notmuch-show.c index 22fa655..4c63959 100644 --- a/notmuch-show.c +++ b/notmuch-show.c @@ -1157,11 +1157,19 @@ notmuch_show_command (notmuch_config_t *config, int argc, char *argv[]) const char **search_exclude_tags; size_t search_exclude_tags_length; unsigned int i; + notmuch_status_t status; search_exclude_tags = notmuch_config_get_search_exclude_tags (config, &search_exclude_tags_length); - for (i = 0; i < search_exclude_tags_length; i++) - notmuch_query_add_tag_exclude (query, search_exclude_tags[i]); + + for (i = 0; i < search_exclude_tags_length; i++) { + status = notmuch_query_add_tag_exclude (query, search_exclude_tags[i]); + if (status && status != NOTMUCH_STATUS_IGNORED) { + print_status_query ("notmuch show", query, status); + ret = -1; + goto DONE; + } + } if (exclude == EXCLUDE_FALSE) { notmuch_query_set_omit_excluded (query, FALSE); @@ -1171,6 +1179,7 @@ notmuch_show_command (notmuch_config_t *config, int argc, char *argv[]) ret = do_show (config, query, format, sprinter, ¶ms); } + DONE: notmuch_crypto_cleanup (¶ms.crypto); notmuch_query_destroy (query); notmuch_database_destroy (notmuch); -- 2.9.3