This commit replaces the --no-exclude option with a --with-excluded option. The output is identical in all cases except output-summary. In this case they output exactly the same thread lines. They differ in that with the new option the match count (i.e., the x in [x/n] in the output) is the number of matching non-excluded messages rather than the number of matching messages. It also change the behaviour when the --with-excluded option is not set (for output=summary): it no longer returns threads only matching in excluded messages. This is neccesary to keep the cli output uncluttered and for speed reasons. --- man/man1/notmuch-search.1 | 6 ++++-- notmuch-search.c | 20 +++++++++++--------- test/search | 9 ++++----- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/man/man1/notmuch-search.1 b/man/man1/notmuch-search.1 index 8426aa3..e46ae68 100644 --- a/man/man1/notmuch-search.1 +++ b/man/man1/notmuch-search.1 @@ -114,9 +114,11 @@ Limit the number of displayed results to N. .RS 4 .TP 4 -.BR \-\-no\-exclude +.BR \-\-with\-excluded -Do not exclude the messages matching search.exclude_tags in the config file. +Include messages matching search.exclude_tags from the config file in +the output. Note that, in this case, the summary output shows the +number of matching non-excluded messages for each thread. .RE .SH SEE ALSO diff --git a/notmuch-search.c b/notmuch-search.c index f6061e4..4af19b5 100644 --- a/notmuch-search.c +++ b/notmuch-search.c @@ -210,9 +210,6 @@ do_search_threads (const search_format_t *format, int first_thread = 1; int i; - if (output == OUTPUT_THREADS) - notmuch_query_set_omit_excluded_messages (query, TRUE); - if (offset < 0) { offset += notmuch_query_count_threads (query); if (offset < 0) @@ -303,8 +300,6 @@ do_search_messages (const search_format_t *format, int first_message = 1; int i; - notmuch_query_set_omit_excluded_messages (query, TRUE); - if (offset < 0) { offset += notmuch_query_count_messages (query); if (offset < 0) @@ -376,7 +371,6 @@ do_search_tags (notmuch_database_t *notmuch, const char *tag; int first_tag = 1; - notmuch_query_set_omit_excluded_messages (query, TRUE); /* should the following only special case if no excluded terms * specified? */ @@ -435,7 +429,7 @@ notmuch_search_command (void *ctx, int argc, char *argv[]) output_t output = OUTPUT_SUMMARY; int offset = 0; int limit = -1; /* unlimited */ - notmuch_bool_t no_exclude = FALSE; + notmuch_bool_t with_excluded = FALSE; unsigned int i; enum { NOTMUCH_FORMAT_JSON, NOTMUCH_FORMAT_TEXT } @@ -457,7 +451,7 @@ notmuch_search_command (void *ctx, int argc, char *argv[]) { "files", OUTPUT_FILES }, { "tags", OUTPUT_TAGS }, { 0, 0 } } }, - { NOTMUCH_OPT_BOOLEAN, &no_exclude, "no-exclude", 'd', 0 }, + { NOTMUCH_OPT_BOOLEAN, &with_excluded, "with-excluded", 'd', 0 }, { NOTMUCH_OPT_INT, &offset, "offset", 'O', 0 }, { NOTMUCH_OPT_INT, &limit, "limit", 'L', 0 }, { 0, 0, 0, 0, 0 } @@ -505,7 +499,13 @@ notmuch_search_command (void *ctx, int argc, char *argv[]) notmuch_query_set_sort (query, sort); - if (!no_exclude) { + /* If we have --with-excluded we could use + * notmuch_query_set_with_excluded, but it is simpler not to set + * the exclude tags in the first place. The one exception is the + * summary output where we do need to use + * notmuch_query_set_with_excluded as we do want the counts to + * reflect the excludes. */ + if (!with_excluded || output == OUTPUT_SUMMARY) { const char **search_exclude_tags; size_t search_exclude_tags_length; @@ -513,6 +513,8 @@ notmuch_search_command (void *ctx, int argc, char *argv[]) (config, &search_exclude_tags_length); for (i = 0; i < search_exclude_tags_length; i++) notmuch_query_add_tag_exclude (query, search_exclude_tags[i]); + if (output == OUTPUT_SUMMARY && with_excluded) + notmuch_query_set_with_excluded_messages (query, TRUE); } switch (output) { diff --git a/test/search b/test/search index 081f60c..6d26f56 100755 --- a/test/search +++ b/test/search @@ -136,8 +136,7 @@ generate_message '[subject]="Deleted"' notmuch new > /dev/null notmuch tag +deleted id:$gen_msg_id output=$(notmuch search subject:deleted | notmuch_search_sanitize) -test_expect_equal "$output" "thread:XXX 2001-01-05 [1/1] Notmuch Test Suite; Not deleted (inbox unread) -thread:XXX 2001-01-05 [0/1] Notmuch Test Suite; Deleted (deleted inbox unread)" +test_expect_equal "$output" "thread:XXX 2001-01-05 [1/1] Notmuch Test Suite; Not deleted (inbox unread)" test_begin_subtest "Exclude \"deleted\" messages from search, overridden" output=$(notmuch search subject:deleted and tag:deleted | notmuch_search_sanitize) @@ -149,10 +148,10 @@ output=$(notmuch search subject:deleted | notmuch_search_sanitize) test_expect_equal "$output" "thread:XXX 2001-01-05 [1/1] Notmuch Test Suite; Not deleted (inbox unread) thread:XXX 2001-01-05 [1/2] Notmuch Test Suite; Not deleted reply (deleted inbox unread)" -test_begin_subtest "Don't exclude \"deleted\" messages when --no-exclude specified" -output=$(notmuch search --no-exclude subject:deleted | notmuch_search_sanitize) +test_begin_subtest "Don't exclude \"deleted\" messages when --with-excluded specified" +output=$(notmuch search --with-excluded subject:deleted | notmuch_search_sanitize) test_expect_equal "$output" "thread:XXX 2001-01-05 [1/1] Notmuch Test Suite; Not deleted (inbox unread) -thread:XXX 2001-01-05 [2/2] Notmuch Test Suite; Deleted (deleted inbox unread)" +thread:XXX 2001-01-05 [1/2] Notmuch Test Suite; Not deleted reply (deleted inbox unread)" test_begin_subtest "Don't exclude \"deleted\" messages from search if not configured" notmuch config set search.exclude_tags -- 1.7.2.3