mirror of
https://git.notmuchmail.org/git/notmuch
synced 2024-11-24 11:58:10 +01:00
lib: make notmuch_query_add_tag_exclude return a status value
Since this is an ABI breaking change, but we already bumped the SONAME for the next release
This commit is contained in:
parent
3721bd45d7
commit
242d5a3ed5
5 changed files with 49 additions and 19 deletions
|
@ -179,6 +179,11 @@ typedef enum _notmuch_status {
|
|||
* passed to a function expecting an absolute path.
|
||||
*/
|
||||
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);
|
||||
|
||||
/**
|
||||
|
|
15
lib/query.cc
15
lib/query.cc
|
@ -177,29 +177,22 @@ 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;
|
||||
char *term;
|
||||
|
||||
status = _notmuch_query_ensure_parsed (query);
|
||||
/* The following is not ideal error handling, but to avoid
|
||||
* breaking the ABI, we can live with it for now. In particular at
|
||||
* least in the notmuch CLI, any syntax error in the query is
|
||||
* caught in a later call to _notmuch_query_ensure_parsed with a
|
||||
* better error path.
|
||||
*
|
||||
* TODO: add status return to this function.
|
||||
*/
|
||||
if (status)
|
||||
return;
|
||||
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
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -1177,11 +1177,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);
|
||||
|
@ -1191,6 +1199,7 @@ notmuch_show_command (notmuch_config_t *config, int argc, char *argv[])
|
|||
ret = do_show (config, query, formatter, sprinter, ¶ms);
|
||||
}
|
||||
|
||||
DONE:
|
||||
notmuch_crypto_cleanup (¶ms.crypto);
|
||||
notmuch_query_destroy (query);
|
||||
notmuch_database_destroy (notmuch);
|
||||
|
|
Loading…
Reference in a new issue