unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* "search --duplicate=2 --output=messages" is deranged
@ 2014-10-29 17:05 David Edmondson
  2014-10-29 19:30 ` [PATCH] cli: notmuch search --duplicate=N is only supported with --output=files Jani Nikula
  2014-11-25 19:49 ` "search --duplicate=2 --output=messages" is deranged David Bremner
  0 siblings, 2 replies; 6+ messages in thread
From: David Edmondson @ 2014-10-29 17:05 UTC (permalink / raw)
  To: notmuch

Consider:

: disaster-area; notmuch search --output=files id:87hbph5yww.fsf@aw.hh.sledj.net
/home/dme/Maildir/mail/list/notmuch/xx01550
: disaster-area; notmuch search --duplicate=2 --output=files id:87hbph5yww.fsf@aw.hh.sledj.net
: disaster-area; notmuch search --duplicate=2 --output=messages id:87hbph5yww.fsf@aw.hh.sledj.net
id:87hbph5yww.fsf@aw.hh.sledj.net
: disaster-area; 

There's only one file, but the last search which asks for results where
there are more than one reports the message id.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH] cli: notmuch search --duplicate=N is only supported with --output=files
  2014-10-29 17:05 "search --duplicate=2 --output=messages" is deranged David Edmondson
@ 2014-10-29 19:30 ` Jani Nikula
  2014-10-30  8:19   ` David Edmondson
  2014-11-25 19:49 ` "search --duplicate=2 --output=messages" is deranged David Bremner
  1 sibling, 1 reply; 6+ messages in thread
From: Jani Nikula @ 2014-10-29 19:30 UTC (permalink / raw)
  To: notmuch, David Edmondson

Check the supported combination, and bail out for other combinations.
---
 notmuch-search.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/notmuch-search.c b/notmuch-search.c
index bc9be4593ecc..3bb5a7fbc885 100644
--- a/notmuch-search.c
+++ b/notmuch-search.c
@@ -387,6 +387,11 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])
     if (opt_index < 0)
 	return EXIT_FAILURE;
 
+    if (output != OUTPUT_FILES && dupe != -1) {
+	fprintf (stderr, "Error: --duplicate=N is only supported with --output=files.\n");
+	return EXIT_FAILURE;
+    }
+
     switch (format_sel) {
     case NOTMUCH_FORMAT_TEXT:
 	format = sprinter_text_create (config, stdout);
-- 
2.1.1

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] cli: notmuch search --duplicate=N is only supported with --output=files
  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     ` [PATCH] cli: add support for notmuch search --duplicate=N with --output=messages Jani Nikula
  0 siblings, 1 reply; 6+ messages in thread
From: David Edmondson @ 2014-10-30  8:19 UTC (permalink / raw)
  To: Jani Nikula, notmuch

This works, in so much as it doesn't allow the deranged behaviour.

Consequentially, --duplicate seems a bit useless. Unless I feed it a
single id: as an argument (in which case I could use --output=files), I
have to figure out which of the files output are duplicates of each
other and which are from different messages. How is that useful?

On Wed, Oct 29 2014, Jani Nikula wrote:
> Check the supported combination, and bail out for other combinations.
> ---
>  notmuch-search.c | 5 +++++
>  1 file changed, 5 insertions(+)
>
> diff --git a/notmuch-search.c b/notmuch-search.c
> index bc9be4593ecc..3bb5a7fbc885 100644
> --- a/notmuch-search.c
> +++ b/notmuch-search.c
> @@ -387,6 +387,11 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])
>      if (opt_index < 0)
>  	return EXIT_FAILURE;
>  
> +    if (output != OUTPUT_FILES && dupe != -1) {
> +	fprintf (stderr, "Error: --duplicate=N is only supported with --output=files.\n");
> +	return EXIT_FAILURE;
> +    }
> +
>      switch (format_sel) {
>      case NOTMUCH_FORMAT_TEXT:
>  	format = sprinter_text_create (config, stdout);
> -- 
> 2.1.1

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH] cli: add support for notmuch search --duplicate=N with --output=messages
  2014-10-30  8:19   ` David Edmondson
@ 2014-10-30 21:44     ` Jani Nikula
  2014-10-31  7:14       ` David Edmondson
  0 siblings, 1 reply; 6+ messages in thread
From: Jani Nikula @ 2014-10-30 21:44 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            | 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

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] cli: add support for notmuch search --duplicate=N with --output=messages
  2014-10-30 21:44     ` [PATCH] cli: add support for notmuch search --duplicate=N with --output=messages Jani Nikula
@ 2014-10-31  7:14       ` David Edmondson
  0 siblings, 0 replies; 6+ messages in thread
From: David Edmondson @ 2014-10-31  7:14 UTC (permalink / raw)
  To: Jani Nikula, notmuch

On Thu, Oct 30 2014, Jani Nikula wrote:
> Print the message IDs of all messages matching the search terms that
> have at least N files associated with them.

Briefly tested as working. I commend this patch to the masters of push.

Thanks Jani!

> ---
>  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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: "search --duplicate=2 --output=messages" is deranged
  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-11-25 19:49 ` David Bremner
  1 sibling, 0 replies; 6+ messages in thread
From: David Bremner @ 2014-11-25 19:49 UTC (permalink / raw)
  To: David Edmondson, notmuch

David Edmondson <dme@dme.org> writes:

> Consider:
>
> : disaster-area; notmuch search --output=files id:87hbph5yww.fsf@aw.hh.sledj.net
> /home/dme/Maildir/mail/list/notmuch/xx01550
> : disaster-area; notmuch search --duplicate=2 --output=files id:87hbph5yww.fsf@aw.hh.sledj.net
> : disaster-area; notmuch search --duplicate=2 --output=messages id:87hbph5yww.fsf@aw.hh.sledj.net
> id:87hbph5yww.fsf@aw.hh.sledj.net
> : disaster-area; 
>
> There's only one file, but the last search which asks for results where
> there are more than one reports the message id.

For the record, this was fixed in commit 4366b9b88c63242

d 

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2014-11-25 19:49 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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     ` [PATCH] cli: add support for notmuch search --duplicate=N with --output=messages Jani Nikula
2014-10-31  7:14       ` David Edmondson
2014-11-25 19:49 ` "search --duplicate=2 --output=messages" is deranged David Bremner

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).