From: Jani Nikula <jani@nikula.org>
To: notmuch@notmuchmail.org
Subject: [PATCH] cli: add support for notmuch search --duplicate=N with --output=messages
Date: Thu, 30 Oct 2014 23:44:49 +0200 [thread overview]
Message-ID: <1414705489-30771-1-git-send-email-jani@nikula.org> (raw)
In-Reply-To: <m28ujy6kba.fsf@dme.org>
Print the message IDs of all messages matching the search terms that
have at least N files associated with them.
---
doc/man1/notmuch-search.rst | 12 ++++++++----
notmuch-search.c | 34 ++++++++++++++++++++++++++++++----
2 files changed, 38 insertions(+), 8 deletions(-)
diff --git a/doc/man1/notmuch-search.rst b/doc/man1/notmuch-search.rst
index 90160f21e23c..aeba4bf604f6 100644
--- a/doc/man1/notmuch-search.rst
+++ b/doc/man1/notmuch-search.rst
@@ -122,10 +122,14 @@ Supported options for **search** include
rather than the number of matching messages.
``--duplicate=N``
- Effective with ``--output=files``, output the Nth filename
- associated with each message matching the query (N is 1-based).
- If N is greater than the number of files associated with the
- message, don't print anything.
+ For ``--output=files``, output the Nth filename associated
+ with each message matching the query (N is 1-based). If N is
+ greater than the number of files associated with the message,
+ don't print anything.
+
+ For ``--output=messages``, only output message IDs of messages
+ matching the search terms that have at least N filenames
+ associated with them.
Note that this option is orthogonal with the **folder:** search
prefix. The prefix matches messages based on filenames. This
diff --git a/notmuch-search.c b/notmuch-search.c
index bc9be4593ecc..2bf876fd5abf 100644
--- a/notmuch-search.c
+++ b/notmuch-search.c
@@ -215,6 +215,24 @@ do_search_threads (sprinter_t *format,
}
static int
+_count_filenames (notmuch_message_t *message)
+{
+ notmuch_filenames_t *filenames;
+ int i = 0;
+
+ filenames = notmuch_message_get_filenames (message);
+
+ while (notmuch_filenames_valid (filenames)) {
+ notmuch_filenames_move_to_next (filenames);
+ i++;
+ }
+
+ notmuch_filenames_destroy (filenames);
+
+ return i;
+}
+
+static int
do_search_messages (sprinter_t *format,
notmuch_query_t *query,
output_t output,
@@ -265,10 +283,13 @@ do_search_messages (sprinter_t *format,
notmuch_filenames_destroy( filenames );
} else { /* output == OUTPUT_MESSAGES */
- format->set_prefix (format, "id");
- format->string (format,
- notmuch_message_get_message_id (message));
- format->separator (format);
+ /* special case 1 for speed */
+ if (dupe <= 1 || dupe <= _count_filenames (message)) {
+ format->set_prefix (format, "id");
+ format->string (format,
+ notmuch_message_get_message_id (message));
+ format->separator (format);
+ }
}
notmuch_message_destroy (message);
@@ -387,6 +408,11 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])
if (opt_index < 0)
return EXIT_FAILURE;
+ if (output != OUTPUT_FILES && output != OUTPUT_MESSAGES && dupe != -1) {
+ fprintf (stderr, "Error: --duplicate=N is only supported with --output=files and --output=messages.\n");
+ return EXIT_FAILURE;
+ }
+
switch (format_sel) {
case NOTMUCH_FORMAT_TEXT:
format = sprinter_text_create (config, stdout);
--
2.1.1
next prev parent reply other threads:[~2014-10-30 21:45 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-10-29 17:05 "search --duplicate=2 --output=messages" is deranged David Edmondson
2014-10-29 19:30 ` [PATCH] cli: notmuch search --duplicate=N is only supported with --output=files Jani Nikula
2014-10-30 8:19 ` David Edmondson
2014-10-30 21:44 ` Jani Nikula [this message]
2014-10-31 7:14 ` [PATCH] cli: add support for notmuch search --duplicate=N with --output=messages David Edmondson
2014-11-25 19:49 ` "search --duplicate=2 --output=messages" is deranged 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=1414705489-30771-1-git-send-email-jani@nikula.org \
--to=jani@nikula.org \
--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).