From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 25345431FAE for ; Thu, 15 Mar 2012 11:42:21 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: 0.201 X-Spam-Level: X-Spam-Status: No, score=0.201 tagged_above=-999 required=5 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_ENVFROM_END_DIGIT=1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id BJ1UZ2NHUiRu for ; Thu, 15 Mar 2012 11:42:18 -0700 (PDT) Received: from mail-we0-f181.google.com (mail-we0-f181.google.com [74.125.82.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id A2AA9431E62 for ; Thu, 15 Mar 2012 11:42:16 -0700 (PDT) Received: by mail-we0-f181.google.com with SMTP id m13so3528469wer.26 for ; Thu, 15 Mar 2012 11:42:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=hT1hrr94WGX1539QJetu5XO8XpS8WNqFx8L+w0uwasc=; b=KJM07sj5lIAH2npw1d44yqF0VZPB27xZOhsBbcOnm0rUnOFFmjtwZHg4ofF6epxIvv XdW1wodCgJ1fJQ/k65udInAgyN+FV+A4cSMDSNu1TU283w8a6gkRiReEnxPlEP9QzNTV n+5THlxrCMYeMaVsE9UpJg+aS0/fGXRpCL0OKI3ovLyvK05kU4zdp6mzyUGqJ74R+Z6C KfyDdOpmvN5kSLzhVDVFsocSvMSu6ceHb53SKM9AQXMiLqSghDiBpUXgwiNEJX5KgH/b 6NiU9FkiwGJ5IIMSSimoA6lcM7uEgxp827kcVxZmVntvYkWkwWliPiDQdr0UtEGagrd3 cVsQ== Received: by 10.216.134.2 with SMTP id r2mr4737610wei.31.1331836936311; Thu, 15 Mar 2012 11:42:16 -0700 (PDT) Received: from localhost (94-192-233-223.zone6.bethere.co.uk. [94.192.233.223]) by mx.google.com with ESMTPS id fw5sm7088634wib.0.2012.03.15.11.42.15 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 15 Mar 2012 11:42:15 -0700 (PDT) From: Mark Walters To: notmuch@notmuchmail.org Subject: [PATCH 3/5] cli: move search to the new --exclude= naming scheme. Date: Thu, 15 Mar 2012 18:42:03 +0000 Message-Id: <1331836925-31437-4-git-send-email-markwalters1009@gmail.com> X-Mailer: git-send-email 1.7.9.1 In-Reply-To: <1331836925-31437-1-git-send-email-markwalters1009@gmail.com> References: <1331836925-31437-1-git-send-email-markwalters1009@gmail.com> X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 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: Thu, 15 Mar 2012 18:42:21 -0000 This commit replaces the --no-exclude option with a --exclude=(true|false|flag) option. The default is to omit the excluded messages. The flag option only makes sense if output=summary (as otherwise there is nowhere to print the flag). In summary output exclude=false and exclude=flag give almost identical output: they differ in that with the exclude=flag 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. Note this changes the default for output=summary when no --exclude= option is given: it used to default to flag and now defaults to true (i.e. omit excluded messages). This is neccesary to keep the cli output uncluttered and for speed reasons. --- man/man1/notmuch-search.1 | 12 +++++++++--- notmuch-search.c | 32 +++++++++++++++++++++++--------- test/search | 13 ++++++------- 3 files changed, 38 insertions(+), 19 deletions(-) diff --git a/man/man1/notmuch-search.1 b/man/man1/notmuch-search.1 index 8426aa3..49fbd0d 100644 --- a/man/man1/notmuch-search.1 +++ b/man/man1/notmuch-search.1 @@ -114,9 +114,15 @@ Limit the number of displayed results to N. .RS 4 .TP 4 -.BR \-\-no\-exclude - -Do not exclude the messages matching search.exclude_tags in the config file. +.BR \-\-exclude=(true|false|flag) + +Specify whether to omit messages matching search.tag_exclude from the +search results (the default) or not. The extra option +.B flag +only has an effect when +.B --output=summary +In this case all matching threads are returned but the "match count" +is the number of matching non-excluded messages in the thread. .RE .SH SEE ALSO diff --git a/notmuch-search.c b/notmuch-search.c index f6061e4..fe18a93 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? */ @@ -422,6 +416,12 @@ do_search_tags (notmuch_database_t *notmuch, return 0; } +enum { + EXCLUDE_TRUE, + EXCLUDE_FALSE, + EXCLUDE_FLAG, +}; + int notmuch_search_command (void *ctx, int argc, char *argv[]) { @@ -435,7 +435,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; + int exclude = EXCLUDE_TRUE; unsigned int i; enum { NOTMUCH_FORMAT_JSON, NOTMUCH_FORMAT_TEXT } @@ -457,7 +457,11 @@ 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_KEYWORD, &exclude, "exclude", 'x', + (notmuch_keyword_t []){ { "true", EXCLUDE_TRUE }, + { "false", EXCLUDE_FALSE }, + { "flag", EXCLUDE_FLAG }, + { 0, 0 } } }, { NOTMUCH_OPT_INT, &offset, "offset", 'O', 0 }, { NOTMUCH_OPT_INT, &limit, "limit", 'L', 0 }, { 0, 0, 0, 0, 0 } @@ -505,7 +509,15 @@ notmuch_search_command (void *ctx, int argc, char *argv[]) notmuch_query_set_sort (query, sort); - if (!no_exclude) { + if (exclude == EXCLUDE_FLAG && output != OUTPUT_SUMMARY) { + /* if we are not doing summary output there is no where to + * print the excluded flag so fall back on including the + * excluded messages */ + fprintf (stderr, "Cannot flag excluded messages with this output: fall back on just including them\n"); + exclude = EXCLUDE_FALSE; + } + + if (exclude == EXCLUDE_TRUE || exclude == EXCLUDE_FLAG) { const char **search_exclude_tags; size_t search_exclude_tags_length; @@ -513,6 +525,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 (exclude == EXCLUDE_FLAG) + notmuch_query_set_omit_excluded_messages (query, FALSE); } switch (output) { diff --git a/test/search b/test/search index 17af6a2..318fdb8 100755 --- a/test/search +++ b/test/search @@ -138,15 +138,14 @@ notmuch new > /dev/null notmuch tag +deleted id:$gen_msg_id 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 message search" output=$(notmuch search --output=messages subject:deleted | notmuch_search_sanitize) test_expect_equal "$output" "id:$not_deleted_id" -test_begin_subtest "Exclude \"deleted\" messages from message search (no-exclude)" -output=$(notmuch search --no-exclude --output=messages subject:deleted | notmuch_search_sanitize) +test_begin_subtest "Exclude \"deleted\" messages from message search --exclude=false" +output=$(notmuch search --exclude=false --output=messages subject:deleted | notmuch_search_sanitize) test_expect_equal "$output" "id:$not_deleted_id id:$deleted_id" @@ -166,10 +165,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 --exclude=flag specified" +output=$(notmuch search --exclude=flag 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.9.1