* [PATCH v2 0/2] cli: search --duplicate=N with --output=messages
@ 2014-11-01 9:31 Jani Nikula
2014-11-01 9:31 ` [PATCH v2 1/2] cli: add support for notmuch " Jani Nikula
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Jani Nikula @ 2014-11-01 9:31 UTC (permalink / raw)
To: notmuch
This is v2 of [1], rebased, tests added, no functional changes.
BR,
Jani.
[1] id:1414705489-30771-1-git-send-email-jani@nikula.org
Jani Nikula (2):
cli: add support for notmuch search --duplicate=N with
--output=messages
test: add tests for --output=messages --duplicate=N
doc/man1/notmuch-search.rst | 12 ++++++++----
notmuch-search.c | 35 +++++++++++++++++++++++++++++++----
test/T090-search-output.sh | 37 +++++++++++++++++++++++++++++++++++++
3 files changed, 76 insertions(+), 8 deletions(-)
--
2.1.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2 1/2] cli: add support for notmuch search --duplicate=N with --output=messages
2014-11-01 9:31 [PATCH v2 0/2] cli: search --duplicate=N with --output=messages Jani Nikula
@ 2014-11-01 9:31 ` Jani Nikula
2014-11-02 19:03 ` David Bremner
2014-11-01 9:31 ` [PATCH v2 2/2] test: add tests for --output=messages --duplicate=N Jani Nikula
2014-11-01 10:06 ` [PATCH v2 0/2] cli: search --duplicate=N with --output=messages Tomi Ollila
2 siblings, 1 reply; 5+ messages in thread
From: Jani Nikula @ 2014-11-01 9:31 UTC (permalink / raw)
To: notmuch
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 | 35 +++++++++++++++++++++++++++++++----
2 files changed, 39 insertions(+), 8 deletions(-)
diff --git a/doc/man1/notmuch-search.rst b/doc/man1/notmuch-search.rst
index b6607c922cc0..8110086eff4f 100644
--- a/doc/man1/notmuch-search.rst
+++ b/doc/man1/notmuch-search.rst
@@ -142,10 +142,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 671fe4139981..6345fb6280ac 100644
--- a/notmuch-search.c
+++ b/notmuch-search.c
@@ -311,6 +311,24 @@ process_address_header (const search_options_t *opt, const char *value)
}
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 (search_options_t *opt)
{
notmuch_message_t *message;
@@ -357,10 +375,13 @@ do_search_messages (search_options_t *opt)
notmuch_filenames_destroy( filenames );
} else if (opt->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 (opt->dupe <= 1 || opt->dupe <= _count_filenames (message)) {
+ format->set_prefix (format, "id");
+ format->string (format,
+ notmuch_message_get_message_id (message));
+ format->separator (format);
+ }
} else {
if (opt->output & OUTPUT_SENDER) {
const char *addrs;
@@ -503,6 +524,12 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])
if (! opt.output)
opt.output = OUTPUT_SUMMARY;
+ if (opt.output != OUTPUT_FILES && opt.output != OUTPUT_MESSAGES &&
+ opt.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:
opt.format = sprinter_text_create (config, stdout);
--
2.1.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v2 2/2] test: add tests for --output=messages --duplicate=N
2014-11-01 9:31 [PATCH v2 0/2] cli: search --duplicate=N with --output=messages Jani Nikula
2014-11-01 9:31 ` [PATCH v2 1/2] cli: add support for notmuch " Jani Nikula
@ 2014-11-01 9:31 ` Jani Nikula
2014-11-01 10:06 ` [PATCH v2 0/2] cli: search --duplicate=N with --output=messages Tomi Ollila
2 siblings, 0 replies; 5+ messages in thread
From: Jani Nikula @ 2014-11-01 9:31 UTC (permalink / raw)
To: notmuch
Basic smoke tests for the feature, nothing fancy.
---
test/T090-search-output.sh | 37 +++++++++++++++++++++++++++++++++++++
1 file changed, 37 insertions(+)
diff --git a/test/T090-search-output.sh b/test/T090-search-output.sh
index 947d572ebeff..fe2ec9af8c2a 100755
--- a/test/T090-search-output.sh
+++ b/test/T090-search-output.sh
@@ -122,6 +122,24 @@ id:1258471718-6781-1-git-send-email-dottedmag@dottedmag.net
EOF
test_expect_equal_file OUTPUT EXPECTED
+test_begin_subtest "--output=messages --duplicate=1"
+notmuch search --output=messages --duplicate=1 '*' >OUTPUT
+# reuse same EXPECTED as above
+test_expect_equal_file OUTPUT EXPECTED
+
+test_begin_subtest "--output=messages --duplicate=2"
+notmuch search --output=messages --duplicate=2 '*' >OUTPUT
+cat <<EOF >EXPECTED
+id:20091117232137.GA7669@griffis1.net
+EOF
+test_expect_equal_file OUTPUT EXPECTED
+
+test_begin_subtest "--output=messages --duplicate=3"
+notmuch search --output=messages --duplicate=3 '*' >OUTPUT
+cat <<EOF >EXPECTED
+EOF
+test_expect_equal_file OUTPUT EXPECTED
+
test_begin_subtest "--output=messages --format=json"
notmuch search --format=json --output=messages '*' >OUTPUT
cat <<EOF >EXPECTED
@@ -180,6 +198,25 @@ cat <<EOF >EXPECTED
EOF
test_expect_equal_file OUTPUT EXPECTED
+test_begin_subtest "--output=messages --format=json --duplicate=1"
+notmuch search --output=messages --format=json --duplicate=1 '*' >OUTPUT
+# reuse same EXPECTED as above
+test_expect_equal_file OUTPUT EXPECTED
+
+test_begin_subtest "--output=messages --format=json --duplicate=2"
+notmuch search --output=messages --format=json --duplicate=2 '*' >OUTPUT
+cat <<EOF >EXPECTED
+["20091117232137.GA7669@griffis1.net"]
+EOF
+test_expect_equal_file OUTPUT EXPECTED
+
+test_begin_subtest "--output=messages --format=json --duplicate=3"
+notmuch search --output=messages --format=json --duplicate=3 '*' >OUTPUT
+cat <<EOF >EXPECTED
+[]
+EOF
+test_expect_equal_file OUTPUT EXPECTED
+
test_begin_subtest "--output=files"
notmuch search --output=files '*' | notmuch_search_files_sanitize | sort >OUTPUT
cat <<EOF >EXPECTED
--
2.1.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v2 0/2] cli: search --duplicate=N with --output=messages
2014-11-01 9:31 [PATCH v2 0/2] cli: search --duplicate=N with --output=messages Jani Nikula
2014-11-01 9:31 ` [PATCH v2 1/2] cli: add support for notmuch " Jani Nikula
2014-11-01 9:31 ` [PATCH v2 2/2] test: add tests for --output=messages --duplicate=N Jani Nikula
@ 2014-11-01 10:06 ` Tomi Ollila
2 siblings, 0 replies; 5+ messages in thread
From: Tomi Ollila @ 2014-11-01 10:06 UTC (permalink / raw)
To: Jani Nikula, notmuch
On Sat, Nov 01 2014, Jani Nikula <jani@nikula.org> wrote:
> This is v2 of [1], rebased, tests added, no functional changes.
Applies cleanly, tests pass. my own tests works as expected.
+1
Tomi
>
> BR,
> Jani.
>
> [1] id:1414705489-30771-1-git-send-email-jani@nikula.org
>
> Jani Nikula (2):
> cli: add support for notmuch search --duplicate=N with
> --output=messages
> test: add tests for --output=messages --duplicate=N
>
> doc/man1/notmuch-search.rst | 12 ++++++++----
> notmuch-search.c | 35 +++++++++++++++++++++++++++++++----
> test/T090-search-output.sh | 37 +++++++++++++++++++++++++++++++++++++
> 3 files changed, 76 insertions(+), 8 deletions(-)
>
> --
> 2.1.1
>
> _______________________________________________
> notmuch mailing list
> notmuch@notmuchmail.org
> http://notmuchmail.org/mailman/listinfo/notmuch
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2 1/2] cli: add support for notmuch search --duplicate=N with --output=messages
2014-11-01 9:31 ` [PATCH v2 1/2] cli: add support for notmuch " Jani Nikula
@ 2014-11-02 19:03 ` David Bremner
0 siblings, 0 replies; 5+ messages in thread
From: David Bremner @ 2014-11-02 19:03 UTC (permalink / raw)
To: Jani Nikula, notmuch
Jani Nikula <jani@nikula.org> writes:
> Print the message IDs of all messages matching the search terms that
> have at least N files associated with them.
Series pushed. I think this probably deserves a brief NEWS entry, what
do you think?
d
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2014-11-02 19:03 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-11-01 9:31 [PATCH v2 0/2] cli: search --duplicate=N with --output=messages Jani Nikula
2014-11-01 9:31 ` [PATCH v2 1/2] cli: add support for notmuch " Jani Nikula
2014-11-02 19:03 ` David Bremner
2014-11-01 9:31 ` [PATCH v2 2/2] test: add tests for --output=messages --duplicate=N Jani Nikula
2014-11-01 10:06 ` [PATCH v2 0/2] cli: search --duplicate=N with --output=messages Tomi Ollila
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).