From: David Bremner <david@tethera.net>
To: notmuch@notmuchmail.org
Subject: [PATCH 4/4] lib: make notmuch_query_add_tag_exclude return a status value
Date: Sat, 18 Feb 2017 11:08:04 -0400 [thread overview]
Message-ID: <20170218150804.26704-5-david@tethera.net> (raw)
In-Reply-To: <20170218150804.26704-1-david@tethera.net>
Since this is an ABI breaking change, bump the SONAME.
---
lib/notmuch.h | 23 +++++++++++++++++++----
lib/query.cc | 7 ++++---
notmuch-count.c | 9 +++++++--
notmuch-search.c | 12 ++++++++++--
notmuch-show.c | 13 +++++++++++--
5 files changed, 51 insertions(+), 13 deletions(-)
diff --git a/lib/notmuch.h b/lib/notmuch.h
index 16da8be9..74043819 100644
--- a/lib/notmuch.h
+++ b/lib/notmuch.h
@@ -55,8 +55,8 @@ NOTMUCH_BEGIN_DECLS
* The library version number. This must agree with the soname
* version in Makefile.local.
*/
-#define LIBNOTMUCH_MAJOR_VERSION 4
-#define LIBNOTMUCH_MINOR_VERSION 4
+#define LIBNOTMUCH_MAJOR_VERSION 5
+#define LIBNOTMUCH_MINOR_VERSION 0
#define LIBNOTMUCH_MICRO_VERSION 0
@@ -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,
+ /**
* One of the arguments violates the preconditions for the
* function, in a way not covered by a more specific argument.
*/
@@ -812,10 +817,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 c0a1cdf8..c027edd3 100644
--- a/lib/query.cc
+++ b/lib/query.cc
@@ -174,7 +174,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;
@@ -182,13 +182,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 35a2aa70..3207c015 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 8c65d5ad..64a98110 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 22fa655a..4c63959f 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.11.0
next prev parent reply other threads:[~2017-02-18 15:08 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-18 15:08 v4 of nondestructive excludes patches David Bremner
2017-02-18 15:08 ` [PATCH 1/4] lib: eagerly parse queries David Bremner
2017-02-18 15:08 ` [PATCH 2/4] lib/query: make query parsing lazy again, keep centralized David Bremner
2017-02-18 15:08 ` [PATCH 3/4] lib: query make exclude handling non-destructive David Bremner
2017-02-18 15:08 ` David Bremner [this message]
2017-03-22 11:54 ` [PATCH 4/4] lib: make notmuch_query_add_tag_exclude return a status value David Bremner
2017-02-25 16:09 ` v5 of nondestructive includes patches David Bremner
2017-02-25 16:09 ` [PATCH 1/3] lib: eagerly parse queries David Bremner
2017-02-25 16:09 ` [PATCH 2/3] lib/query: make query parsing lazy again, keep centralized David Bremner
2017-02-25 16:09 ` [PATCH 3/3] lib: query make exclude handling non-destructive David Bremner
-- strict thread matches above, loose matches on Subject: below --
2016-11-22 2:27 V3 of non-destructive excludes patches David Bremner
2016-11-22 2:27 ` [PATCH 4/4] lib: make notmuch_query_add_tag_exclude return a status value 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=20170218150804.26704-5-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).