unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH v2 0/7] cli: better tooling support for duplicate messages
@ 2013-06-09 11:03 Jani Nikula
  2013-06-09 11:03 ` [PATCH v2 1/7] cli: add --duplicate=N option to notmuch search Jani Nikula
                   ` (7 more replies)
  0 siblings, 8 replies; 16+ messages in thread
From: Jani Nikula @ 2013-06-09 11:03 UTC (permalink / raw)
  To: notmuch

v2 of id:cover.1368467532.git.jani@nikula.org

The only change is switching to 1-based indexing for --duplicate=N option.

Jani.


Jani Nikula (7):
  cli: add --duplicate=N option to notmuch search
  test: test notmuch search --duplicate=N
  man: document notmuch search --duplicate=N
  cli: add --output=files option to notmuch count
  test: test notmuch count --output=files
  man: document notmuch count --output=files
  NEWS: cli options for improved duplicate message handling

 NEWS                      |   12 +++++++++
 man/man1/notmuch-count.1  |   10 ++++++-
 man/man1/notmuch-search.1 |   11 ++++++++
 notmuch-count.c           |   37 ++++++++++++++++++++++++++
 notmuch-search.c          |   18 ++++++++-----
 test/count                |   10 +++++++
 test/search-output        |   65 +++++++++++++++++++++++++++++++++++++++++++++
 7 files changed, 156 insertions(+), 7 deletions(-)

-- 
1.7.10.4

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

* [PATCH v2 1/7] cli: add --duplicate=N option to notmuch search
  2013-06-09 11:03 [PATCH v2 0/7] cli: better tooling support for duplicate messages Jani Nikula
@ 2013-06-09 11:03 ` Jani Nikula
  2013-06-09 20:22   ` Mark Walters
  2013-06-10 15:57   ` [PATCH v3] " Jani Nikula
  2013-06-09 11:03 ` [PATCH v2 2/7] test: test notmuch search --duplicate=N Jani Nikula
                   ` (6 subsequent siblings)
  7 siblings, 2 replies; 16+ messages in thread
From: Jani Nikula @ 2013-06-09 11:03 UTC (permalink / raw)
  To: notmuch

Effective with --output=files, output the Nth filename associated with
each message matching the query (N is 0-based). If N is equal to or
greater than the number of files associated with the message, don't
print anything.
---
 notmuch-search.c |   18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/notmuch-search.c b/notmuch-search.c
index 4323201..196934b 100644
--- a/notmuch-search.c
+++ b/notmuch-search.c
@@ -177,7 +177,8 @@ do_search_messages (sprinter_t *format,
 		    notmuch_query_t *query,
 		    output_t output,
 		    int offset,
-		    int limit)
+		    int limit,
+		    int dupe)
 {
     notmuch_message_t *message;
     notmuch_messages_t *messages;
@@ -206,14 +207,17 @@ do_search_messages (sprinter_t *format,
 	message = notmuch_messages_get (messages);
 
 	if (output == OUTPUT_FILES) {
+	    int j;
 	    filenames = notmuch_message_get_filenames (message);
 
-	    for (;
+	    for (j = 1;
 		 notmuch_filenames_valid (filenames);
-		 notmuch_filenames_move_to_next (filenames))
+		 notmuch_filenames_move_to_next (filenames), j++)
 	    {
-		format->string (format, notmuch_filenames_get (filenames));
-		format->separator (format);
+		if (dupe < 0 || dupe == j) {
+		    format->string (format, notmuch_filenames_get (filenames));
+		    format->separator (format);
+		}
 	    }
 	    
 	    notmuch_filenames_destroy( filenames );
@@ -303,6 +307,7 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])
     int offset = 0;
     int limit = -1; /* unlimited */
     int exclude = EXCLUDE_TRUE;
+    int dupe = -1;
     unsigned int i;
 
     enum {
@@ -339,6 +344,7 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])
                                   { 0, 0 } } },
 	{ NOTMUCH_OPT_INT, &offset, "offset", 'O', 0 },
 	{ NOTMUCH_OPT_INT, &limit, "limit", 'L', 0  },
+	{ NOTMUCH_OPT_INT, &dupe, "duplicate", 'D', 0  },
 	{ 0, 0, 0, 0, 0 }
     };
 
@@ -424,7 +430,7 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])
 	break;
     case OUTPUT_MESSAGES:
     case OUTPUT_FILES:
-	ret = do_search_messages (format, query, output, offset, limit);
+	ret = do_search_messages (format, query, output, offset, limit, dupe);
 	break;
     case OUTPUT_TAGS:
 	ret = do_search_tags (notmuch, format, query);
-- 
1.7.10.4

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

* [PATCH v2 2/7] test: test notmuch search --duplicate=N
  2013-06-09 11:03 [PATCH v2 0/7] cli: better tooling support for duplicate messages Jani Nikula
  2013-06-09 11:03 ` [PATCH v2 1/7] cli: add --duplicate=N option to notmuch search Jani Nikula
@ 2013-06-09 11:03 ` Jani Nikula
  2013-06-09 11:03 ` [PATCH v2 3/7] man: document " Jani Nikula
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 16+ messages in thread
From: Jani Nikula @ 2013-06-09 11:03 UTC (permalink / raw)
  To: notmuch

---
 test/search-output |   65 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 65 insertions(+)

diff --git a/test/search-output b/test/search-output
index c2a87eb..5ccfeaf 100755
--- a/test/search-output
+++ b/test/search-output
@@ -239,6 +239,64 @@ MAIL_DIR/cur/01:2,
 EOF
 test_expect_equal_file OUTPUT EXPECTED
 
+test_begin_subtest "--output=files --duplicate=1"
+notmuch search --output=files --duplicate=1 '*' | sed -e "s,$MAIL_DIR,MAIL_DIR," >OUTPUT
+cat <<EOF >EXPECTED
+MAIL_DIR/cur/52:2,
+MAIL_DIR/cur/53:2,
+MAIL_DIR/cur/50:2,
+MAIL_DIR/cur/49:2,
+MAIL_DIR/cur/48:2,
+MAIL_DIR/cur/47:2,
+MAIL_DIR/cur/46:2,
+MAIL_DIR/cur/45:2,
+MAIL_DIR/cur/44:2,
+MAIL_DIR/cur/43:2,
+MAIL_DIR/cur/42:2,
+MAIL_DIR/cur/41:2,
+MAIL_DIR/cur/40:2,
+MAIL_DIR/cur/39:2,
+MAIL_DIR/cur/38:2,
+MAIL_DIR/cur/37:2,
+MAIL_DIR/cur/36:2,
+MAIL_DIR/cur/35:2,
+MAIL_DIR/cur/34:2,
+MAIL_DIR/cur/33:2,
+MAIL_DIR/cur/32:2,
+MAIL_DIR/cur/31:2,
+MAIL_DIR/cur/30:2,
+MAIL_DIR/cur/29:2,
+MAIL_DIR/cur/28:2,
+MAIL_DIR/cur/27:2,
+MAIL_DIR/cur/26:2,
+MAIL_DIR/cur/25:2,
+MAIL_DIR/cur/24:2,
+MAIL_DIR/cur/23:2,
+MAIL_DIR/cur/22:2,
+MAIL_DIR/cur/21:2,
+MAIL_DIR/cur/19:2,
+MAIL_DIR/cur/18:2,
+MAIL_DIR/cur/20:2,
+MAIL_DIR/cur/17:2,
+MAIL_DIR/cur/16:2,
+MAIL_DIR/cur/15:2,
+MAIL_DIR/cur/14:2,
+MAIL_DIR/cur/13:2,
+MAIL_DIR/cur/12:2,
+MAIL_DIR/cur/11:2,
+MAIL_DIR/cur/10:2,
+MAIL_DIR/cur/09:2,
+MAIL_DIR/cur/08:2,
+MAIL_DIR/cur/06:2,
+MAIL_DIR/cur/05:2,
+MAIL_DIR/cur/04:2,
+MAIL_DIR/cur/03:2,
+MAIL_DIR/cur/07:2,
+MAIL_DIR/cur/02:2,
+MAIL_DIR/cur/01:2,
+EOF
+test_expect_equal_file OUTPUT EXPECTED
+
 test_begin_subtest "--output=files --format=json"
 notmuch search --format=json --output=files '*' | sed -e "s,$MAIL_DIR,MAIL_DIR," >OUTPUT
 cat <<EOF >EXPECTED
@@ -298,6 +356,13 @@ cat <<EOF >EXPECTED
 EOF
 test_expect_equal_file OUTPUT EXPECTED
 
+test_begin_subtest "--output=files --format=json --duplicate=2"
+notmuch search --format=json --output=files --duplicate=2 '*' | sed -e "s,$MAIL_DIR,MAIL_DIR," >OUTPUT
+cat <<EOF >EXPECTED
+["MAIL_DIR/cur/51:2,"]
+EOF
+test_expect_equal_file OUTPUT EXPECTED
+
 test_begin_subtest "--output=tags"
 notmuch search --output=tags '*' >OUTPUT
 cat <<EOF >EXPECTED
-- 
1.7.10.4

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

* [PATCH v2 3/7] man: document notmuch search --duplicate=N
  2013-06-09 11:03 [PATCH v2 0/7] cli: better tooling support for duplicate messages Jani Nikula
  2013-06-09 11:03 ` [PATCH v2 1/7] cli: add --duplicate=N option to notmuch search Jani Nikula
  2013-06-09 11:03 ` [PATCH v2 2/7] test: test notmuch search --duplicate=N Jani Nikula
@ 2013-06-09 11:03 ` Jani Nikula
  2013-06-09 13:20   ` Mark Walters
  2013-06-10 16:28   ` [PATCH v3] " Jani Nikula
  2013-06-09 11:03 ` [PATCH v2 4/7] cli: add --output=files option to notmuch count Jani Nikula
                   ` (4 subsequent siblings)
  7 siblings, 2 replies; 16+ messages in thread
From: Jani Nikula @ 2013-06-09 11:03 UTC (permalink / raw)
  To: notmuch

---
 man/man1/notmuch-search.1 |   11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/man/man1/notmuch-search.1 b/man/man1/notmuch-search.1
index 1c1e049..4d8b3d3 100644
--- a/man/man1/notmuch-search.1
+++ b/man/man1/notmuch-search.1
@@ -158,6 +158,17 @@ but the "match count" is the number of matching non-excluded messages in the
 thread, rather than the number of matching messages.
 .RE
 
+.RS 4
+.TP 4
+.BR \-\-duplicate=N
+
+Effective with
+.BR --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.
+.RE
+
 .SH EXIT STATUS
 
 This command supports the following special exit status codes
-- 
1.7.10.4

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

* [PATCH v2 4/7] cli: add --output=files option to notmuch count
  2013-06-09 11:03 [PATCH v2 0/7] cli: better tooling support for duplicate messages Jani Nikula
                   ` (2 preceding siblings ...)
  2013-06-09 11:03 ` [PATCH v2 3/7] man: document " Jani Nikula
@ 2013-06-09 11:03 ` Jani Nikula
  2013-06-09 11:03 ` [PATCH v2 5/7] test: test notmuch count --output=files Jani Nikula
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 16+ messages in thread
From: Jani Nikula @ 2013-06-09 11:03 UTC (permalink / raw)
  To: notmuch

Add support for querying the total number of files associated with the
messages matching the search. This is mostly useful with an
id:<message-id> query for a single message.
---
 notmuch-count.c |   37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)

diff --git a/notmuch-count.c b/notmuch-count.c
index 8772cff..01e4e30 100644
--- a/notmuch-count.c
+++ b/notmuch-count.c
@@ -24,6 +24,7 @@
 enum {
     OUTPUT_THREADS,
     OUTPUT_MESSAGES,
+    OUTPUT_FILES,
 };
 
 /* The following is to allow future options to be added more easily */
@@ -32,6 +33,38 @@ enum {
     EXCLUDE_FALSE,
 };
 
+static unsigned int
+count_files (notmuch_query_t *query)
+{
+    notmuch_messages_t *messages;
+    notmuch_message_t *message;
+    notmuch_filenames_t *filenames;
+    unsigned int count = 0;
+
+    messages = notmuch_query_search_messages (query);
+    if (messages == NULL)
+	return 0;
+
+    for (;
+	 notmuch_messages_valid (messages);
+	 notmuch_messages_move_to_next (messages)) {
+	message = notmuch_messages_get (messages);
+	filenames = notmuch_message_get_filenames (message);
+
+	for (;
+	     notmuch_filenames_valid (filenames);
+	     notmuch_filenames_move_to_next (filenames))
+	    count++;
+
+	notmuch_filenames_destroy (filenames);
+	notmuch_message_destroy (message);
+    }
+
+    notmuch_messages_destroy (messages);
+
+    return count;
+}
+
 static int
 print_count (notmuch_database_t *notmuch, const char *query_str,
 	     const char **exclude_tags, size_t exclude_tags_length, int output)
@@ -55,6 +88,9 @@ print_count (notmuch_database_t *notmuch, const char *query_str,
     case OUTPUT_THREADS:
 	printf ("%u\n", notmuch_query_count_threads (query));
 	break;
+    case OUTPUT_FILES:
+	printf ("%u\n", count_files (query));
+	break;
     }
 
     notmuch_query_destroy (query);
@@ -102,6 +138,7 @@ notmuch_count_command (notmuch_config_t *config, int argc, char *argv[])
 	{ NOTMUCH_OPT_KEYWORD, &output, "output", 'o',
 	  (notmuch_keyword_t []){ { "threads", OUTPUT_THREADS },
 				  { "messages", OUTPUT_MESSAGES },
+				  { "files", OUTPUT_FILES },
 				  { 0, 0 } } },
 	{ NOTMUCH_OPT_KEYWORD, &exclude, "exclude", 'x',
 	  (notmuch_keyword_t []){ { "true", EXCLUDE_TRUE },
-- 
1.7.10.4

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

* [PATCH v2 5/7] test: test notmuch count --output=files
  2013-06-09 11:03 [PATCH v2 0/7] cli: better tooling support for duplicate messages Jani Nikula
                   ` (3 preceding siblings ...)
  2013-06-09 11:03 ` [PATCH v2 4/7] cli: add --output=files option to notmuch count Jani Nikula
@ 2013-06-09 11:03 ` Jani Nikula
  2013-06-09 11:03 ` [PATCH v2 6/7] man: document " Jani Nikula
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 16+ messages in thread
From: Jani Nikula @ 2013-06-09 11:03 UTC (permalink / raw)
  To: notmuch

---
 test/count |   10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/test/count b/test/count
index 05713fd..da86c8c 100755
--- a/test/count
+++ b/test/count
@@ -28,6 +28,16 @@ test_expect_equal \
     "$((`notmuch search '*' | wc -l`))" \
     "`notmuch count --output=threads '*'`"
 
+test_begin_subtest "files count"
+test_expect_equal \
+    "$((`notmuch search --output=files '*' | wc -l`))" \
+    "`notmuch count --output=files '*'`"
+
+test_begin_subtest "files count for a duplicate message-id"
+test_expect_equal \
+    "2" \
+    "`notmuch count --output=files id:20091117232137.GA7669@griffis1.net`"
+
 test_begin_subtest "count with no matching messages"
 test_expect_equal \
     "0" \
-- 
1.7.10.4

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

* [PATCH v2 6/7] man: document notmuch count --output=files
  2013-06-09 11:03 [PATCH v2 0/7] cli: better tooling support for duplicate messages Jani Nikula
                   ` (4 preceding siblings ...)
  2013-06-09 11:03 ` [PATCH v2 5/7] test: test notmuch count --output=files Jani Nikula
@ 2013-06-09 11:03 ` Jani Nikula
  2013-06-09 11:03 ` [PATCH v2 7/7] NEWS: cli options for improved duplicate message handling Jani Nikula
  2013-06-10 15:30 ` [PATCH v2 0/7] cli: better tooling support for duplicate messages Tomi Ollila
  7 siblings, 0 replies; 16+ messages in thread
From: Jani Nikula @ 2013-06-09 11:03 UTC (permalink / raw)
  To: notmuch

---
 man/man1/notmuch-count.1 |   10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/man/man1/notmuch-count.1 b/man/man1/notmuch-count.1
index 7fc4378..60af631 100644
--- a/man/man1/notmuch-count.1
+++ b/man/man1/notmuch-count.1
@@ -23,7 +23,7 @@ Supported options for
 include
 .RS 4
 .TP 4
-.B \-\-output=(messages|threads)
+.B \-\-output=(messages|threads|files)
 
 .RS 4
 .TP 4
@@ -37,6 +37,14 @@ Output the number of matching messages. This is the default.
 
 Output the number of matching threads.
 .RE
+.RS 4
+.TP 4
+.B files
+
+Output the number of files associated with matching messages. This may
+be bigger than the number of matching messages due to duplicates
+(i.e. multiple files having the same message-id).
+.RE
 .RE
 
 .RS 4
-- 
1.7.10.4

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

* [PATCH v2 7/7] NEWS: cli options for improved duplicate message handling
  2013-06-09 11:03 [PATCH v2 0/7] cli: better tooling support for duplicate messages Jani Nikula
                   ` (5 preceding siblings ...)
  2013-06-09 11:03 ` [PATCH v2 6/7] man: document " Jani Nikula
@ 2013-06-09 11:03 ` Jani Nikula
  2013-06-10 15:30 ` [PATCH v2 0/7] cli: better tooling support for duplicate messages Tomi Ollila
  7 siblings, 0 replies; 16+ messages in thread
From: Jani Nikula @ 2013-06-09 11:03 UTC (permalink / raw)
  To: notmuch

---
 NEWS |   12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/NEWS b/NEWS
index e1806c2..2eb2ded 100644
--- a/NEWS
+++ b/NEWS
@@ -4,6 +4,18 @@ Notmuch 0.16 (2013-MM-DD)
 Command-Line Interface
 ----------------------
 
+New options to better support handling duplicate messages
+
+  If more than one message file is associated with a message-id,
+  `notmuch search --output=files` will print all of them. A new
+  `--duplicate=N` option can be used to specify which duplicate to
+  print for each message.
+
+  `notmuch count` now supports `--output=files` option to output the
+  number of files associated with matching messages. This may be
+  bigger than the number of matching messages due to duplicates
+  (i.e. multiple files having the same message-id).
+
 Decrypting commands explicitly expect a gpg-agent
 
   Decryption in `notmuch show` and `notmuch reply` has only ever
-- 
1.7.10.4

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

* Re: [PATCH v2 3/7] man: document notmuch search --duplicate=N
  2013-06-09 11:03 ` [PATCH v2 3/7] man: document " Jani Nikula
@ 2013-06-09 13:20   ` Mark Walters
  2013-06-09 13:25     ` Mark Walters
  2013-06-10 16:28   ` [PATCH v3] " Jani Nikula
  1 sibling, 1 reply; 16+ messages in thread
From: Mark Walters @ 2013-06-09 13:20 UTC (permalink / raw)
  To: Jani Nikula, notmuch


One thing that slightly bothers me with this set (which in some sense is
already true) is doing a search of the form

notmuch search --output=files folder:<a_folder>

T

On Sun, 09 Jun 2013, Jani Nikula <jani@nikula.org> wrote:
> ---
>  man/man1/notmuch-search.1 |   11 +++++++++++
>  1 file changed, 11 insertions(+)
>
> diff --git a/man/man1/notmuch-search.1 b/man/man1/notmuch-search.1
> index 1c1e049..4d8b3d3 100644
> --- a/man/man1/notmuch-search.1
> +++ b/man/man1/notmuch-search.1
> @@ -158,6 +158,17 @@ but the "match count" is the number of matching non-excluded messages in the
>  thread, rather than the number of matching messages.
>  .RE
>  
> +.RS 4
> +.TP 4
> +.BR \-\-duplicate=N
> +
> +Effective with
> +.BR --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.
> +.RE
> +
>  .SH EXIT STATUS
>  
>  This command supports the following special exit status codes
> -- 
> 1.7.10.4
>
> _______________________________________________
> notmuch mailing list
> notmuch@notmuchmail.org
> http://notmuchmail.org/mailman/listinfo/notmuch

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

* Re: [PATCH v2 3/7] man: document notmuch search --duplicate=N
  2013-06-09 13:20   ` Mark Walters
@ 2013-06-09 13:25     ` Mark Walters
  2013-06-10 16:39       ` Jani Nikula
  0 siblings, 1 reply; 16+ messages in thread
From: Mark Walters @ 2013-06-09 13:25 UTC (permalink / raw)
  To: Jani Nikula, notmuch


Sorry about that: I meant to cancel the message rather than sending it.

What I was wondering was whether we should change the wording of the
manpage to make it clear that notmuch search --output=files returns all
filenames where any of the copies matches the search terms (I think; I
was going to check before sending anything). In particular, 

notmuch search --output=files folder:a_folder may return filenames not
in a_folder

(This is slightly more noticeable with this patch than before as 
notmuch search --output=files --duplicate=1 folder:a_folder could give
no results in folder a_folder

(None of the above is meant to be a criticism of this patch: I have
only sent this email due to my accidental sending of the previous message)

Best wishes

Mark




What IOn Sun, 09 Jun 2013, Mark Walters <markwalters1009@gmail.com> wrote:
> One thing that slightly bothers me with this set (which in some sense is
> already true) is doing a search of the form
>
> notmuch search --output=files folder:<a_folder>
>
> T
>
> On Sun, 09 Jun 2013, Jani Nikula <jani@nikula.org> wrote:
>> ---
>>  man/man1/notmuch-search.1 |   11 +++++++++++
>>  1 file changed, 11 insertions(+)
>>
>> diff --git a/man/man1/notmuch-search.1 b/man/man1/notmuch-search.1
>> index 1c1e049..4d8b3d3 100644
>> --- a/man/man1/notmuch-search.1
>> +++ b/man/man1/notmuch-search.1
>> @@ -158,6 +158,17 @@ but the "match count" is the number of matching non-excluded messages in the
>>  thread, rather than the number of matching messages.
>>  .RE
>>  
>> +.RS 4
>> +.TP 4
>> +.BR \-\-duplicate=N
>> +
>> +Effective with
>> +.BR --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.
>> +.RE
>> +
>>  .SH EXIT STATUS
>>  
>>  This command supports the following special exit status codes
>> -- 
>> 1.7.10.4
>>
>> _______________________________________________
>> notmuch mailing list
>> notmuch@notmuchmail.org
>> http://notmuchmail.org/mailman/listinfo/notmuch

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

* Re: [PATCH v2 1/7] cli: add --duplicate=N option to notmuch search
  2013-06-09 11:03 ` [PATCH v2 1/7] cli: add --duplicate=N option to notmuch search Jani Nikula
@ 2013-06-09 20:22   ` Mark Walters
  2013-06-10 16:49     ` Jani Nikula
  2013-06-10 15:57   ` [PATCH v3] " Jani Nikula
  1 sibling, 1 reply; 16+ messages in thread
From: Mark Walters @ 2013-06-09 20:22 UTC (permalink / raw)
  To: Jani Nikula, notmuch


Overall I like this series and am happy to give it a +1 as is but have a
few comments which might be worth considering.

Is the order of filenames clear? eg is it the order that notmuch new met
them? In particular is duplicate=1 the oldest and duplicate=N the
newest? If so that might be worth mentioning in the manpage.

On Sun, 09 Jun 2013, Jani Nikula <jani@nikula.org> wrote:
> Effective with --output=files, output the Nth filename associated with
> each message matching the query (N is 0-based). If N is equal to or
> greater than the number of files associated with the message, don't
> print anything.
> ---
>  notmuch-search.c |   18 ++++++++++++------
>  1 file changed, 12 insertions(+), 6 deletions(-)
>
> diff --git a/notmuch-search.c b/notmuch-search.c
> index 4323201..196934b 100644
> --- a/notmuch-search.c
> +++ b/notmuch-search.c
> @@ -177,7 +177,8 @@ do_search_messages (sprinter_t *format,
>  		    notmuch_query_t *query,
>  		    output_t output,
>  		    int offset,
> -		    int limit)
> +		    int limit,
> +		    int dupe)
>  {
>      notmuch_message_t *message;
>      notmuch_messages_t *messages;
> @@ -206,14 +207,17 @@ do_search_messages (sprinter_t *format,
>  	message = notmuch_messages_get (messages);
>  
>  	if (output == OUTPUT_FILES) {
> +	    int j;
>  	    filenames = notmuch_message_get_filenames (message);
>  
> -	    for (;
> +	    for (j = 1;
>  		 notmuch_filenames_valid (filenames);
> -		 notmuch_filenames_move_to_next (filenames))
> +		 notmuch_filenames_move_to_next (filenames), j++)
>  	    {
> -		format->string (format, notmuch_filenames_get (filenames));
> -		format->separator (format);
> +		if (dupe < 0 || dupe == j) {
> +		    format->string (format, notmuch_filenames_get (filenames));
> +		    format->separator (format);

Is it deliberate that dupe == 0 is not covered? If my newest oldest
thing above is correct then maybe dupe == 0 could be the all option +N
the Nth oldest and -N the Nth newest. This may be not-trivial enough
it's not worth doing.

> +		}
>  	    }
>  	    
>  	    notmuch_filenames_destroy( filenames );
> @@ -303,6 +307,7 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])
>      int offset = 0;
>      int limit = -1; /* unlimited */
>      int exclude = EXCLUDE_TRUE;
> +    int dupe = -1;
>      unsigned int i;
>  
>      enum {
> @@ -339,6 +344,7 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])
>                                    { 0, 0 } } },
>  	{ NOTMUCH_OPT_INT, &offset, "offset", 'O', 0 },
>  	{ NOTMUCH_OPT_INT, &limit, "limit", 'L', 0  },
> +	{ NOTMUCH_OPT_INT, &dupe, "duplicate", 'D', 0  },
>  	{ 0, 0, 0, 0, 0 }
>      };
>  
> @@ -424,7 +430,7 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])
>  	break;
>      case OUTPUT_MESSAGES:
>      case OUTPUT_FILES:
> -	ret = do_search_messages (format, query, output, offset, limit);
> +	ret = do_search_messages (format, query, output, offset, limit, dupe);

Should there be an error message if duplicate=x is chosen with
output!=files?

Best wishes

Mark


>  	break;
>      case OUTPUT_TAGS:
>  	ret = do_search_tags (notmuch, format, query);
> -- 
> 1.7.10.4
>
> _______________________________________________
> notmuch mailing list
> notmuch@notmuchmail.org
> http://notmuchmail.org/mailman/listinfo/notmuch

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

* Re: [PATCH v2 0/7] cli: better tooling support for duplicate messages
  2013-06-09 11:03 [PATCH v2 0/7] cli: better tooling support for duplicate messages Jani Nikula
                   ` (6 preceding siblings ...)
  2013-06-09 11:03 ` [PATCH v2 7/7] NEWS: cli options for improved duplicate message handling Jani Nikula
@ 2013-06-10 15:30 ` Tomi Ollila
  7 siblings, 0 replies; 16+ messages in thread
From: Tomi Ollila @ 2013-06-10 15:30 UTC (permalink / raw)
  To: Jani Nikula, notmuch

On Sun, Jun 09 2013, Jani Nikula <jani@nikula.org> wrote:

> v2 of id:cover.1368467532.git.jani@nikula.org
>
> The only change is switching to 1-based indexing for --duplicate=N
> option.

The code looks good to me. Mark's comment about showing duplicate file
from another folder than mentioned in query string could be tackled
in manual somehow. 
Also, when you make next version fix the commit message in
id:61ed86f221d65b4dba438cbc2b4c5b77a484a534.1370775663.git.jani@nikula.org
to mention 1-based.

> Jani.

Tomi

BTW: can we track on which machine you're working on by looking
Message-Id:s >;)

>
>
> Jani Nikula (7):
>   cli: add --duplicate=N option to notmuch search
>   test: test notmuch search --duplicate=N
>   man: document notmuch search --duplicate=N
>   cli: add --output=files option to notmuch count
>   test: test notmuch count --output=files
>   man: document notmuch count --output=files
>   NEWS: cli options for improved duplicate message handling
>
>  NEWS                      |   12 +++++++++
>  man/man1/notmuch-count.1  |   10 ++++++-
>  man/man1/notmuch-search.1 |   11 ++++++++
>  notmuch-count.c           |   37 ++++++++++++++++++++++++++
>  notmuch-search.c          |   18 ++++++++-----
>  test/count                |   10 +++++++
>  test/search-output        |   65 +++++++++++++++++++++++++++++++++++++++++++++
>  7 files changed, 156 insertions(+), 7 deletions(-)
>
> -- 
> 1.7.10.4
>
> _______________________________________________
> notmuch mailing list
> notmuch@notmuchmail.org
> http://notmuchmail.org/mailman/listinfo/notmuch

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

* [PATCH v3] cli: add --duplicate=N option to notmuch search
  2013-06-09 11:03 ` [PATCH v2 1/7] cli: add --duplicate=N option to notmuch search Jani Nikula
  2013-06-09 20:22   ` Mark Walters
@ 2013-06-10 15:57   ` Jani Nikula
  1 sibling, 0 replies; 16+ messages in thread
From: Jani Nikula @ 2013-06-10 15:57 UTC (permalink / raw)
  To: notmuch

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.

---

v3: fix commit message, no other changes
---
 notmuch-search.c |   18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/notmuch-search.c b/notmuch-search.c
index 4323201..196934b 100644
--- a/notmuch-search.c
+++ b/notmuch-search.c
@@ -177,7 +177,8 @@ do_search_messages (sprinter_t *format,
 		    notmuch_query_t *query,
 		    output_t output,
 		    int offset,
-		    int limit)
+		    int limit,
+		    int dupe)
 {
     notmuch_message_t *message;
     notmuch_messages_t *messages;
@@ -206,14 +207,17 @@ do_search_messages (sprinter_t *format,
 	message = notmuch_messages_get (messages);
 
 	if (output == OUTPUT_FILES) {
+	    int j;
 	    filenames = notmuch_message_get_filenames (message);
 
-	    for (;
+	    for (j = 1;
 		 notmuch_filenames_valid (filenames);
-		 notmuch_filenames_move_to_next (filenames))
+		 notmuch_filenames_move_to_next (filenames), j++)
 	    {
-		format->string (format, notmuch_filenames_get (filenames));
-		format->separator (format);
+		if (dupe < 0 || dupe == j) {
+		    format->string (format, notmuch_filenames_get (filenames));
+		    format->separator (format);
+		}
 	    }
 	    
 	    notmuch_filenames_destroy( filenames );
@@ -303,6 +307,7 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])
     int offset = 0;
     int limit = -1; /* unlimited */
     int exclude = EXCLUDE_TRUE;
+    int dupe = -1;
     unsigned int i;
 
     enum {
@@ -339,6 +344,7 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])
                                   { 0, 0 } } },
 	{ NOTMUCH_OPT_INT, &offset, "offset", 'O', 0 },
 	{ NOTMUCH_OPT_INT, &limit, "limit", 'L', 0  },
+	{ NOTMUCH_OPT_INT, &dupe, "duplicate", 'D', 0  },
 	{ 0, 0, 0, 0, 0 }
     };
 
@@ -424,7 +430,7 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])
 	break;
     case OUTPUT_MESSAGES:
     case OUTPUT_FILES:
-	ret = do_search_messages (format, query, output, offset, limit);
+	ret = do_search_messages (format, query, output, offset, limit, dupe);
 	break;
     case OUTPUT_TAGS:
 	ret = do_search_tags (notmuch, format, query);
-- 
1.7.10.4

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

* [PATCH v3] man: document notmuch search --duplicate=N
  2013-06-09 11:03 ` [PATCH v2 3/7] man: document " Jani Nikula
  2013-06-09 13:20   ` Mark Walters
@ 2013-06-10 16:28   ` Jani Nikula
  1 sibling, 0 replies; 16+ messages in thread
From: Jani Nikula @ 2013-06-10 16:28 UTC (permalink / raw)
  To: notmuch, Mark Walters

---

v3: clarify dupe vs. folder prefix per Mark's suggestion
---
 man/man1/notmuch-search.1 |   20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/man/man1/notmuch-search.1 b/man/man1/notmuch-search.1
index 1c1e049..957b24b 100644
--- a/man/man1/notmuch-search.1
+++ b/man/man1/notmuch-search.1
@@ -80,6 +80,10 @@ Output the filenames of all messages matching the search terms, either
 one per line (\-\-format=text), separated by null characters
 (\-\-format=text0), as a JSON array (\-\-format=json), or as an
 S-Expression list (\-\-format=sexp).
+
+Note that each message may have multiple filenames associated with it.
+All of them are included in the output, unless limited with the
+\-\-duplicate=N option.
 .RE
 .RS 4
 .TP 4
@@ -158,6 +162,22 @@ but the "match count" is the number of matching non-excluded messages in the
 thread, rather than the number of matching messages.
 .RE
 
+.RS 4
+.TP 4
+.BR \-\-duplicate=N
+
+Effective with
+.BR --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.
+
+Note that this option is orthogonal with the
+.BR folder:
+search prefix. The prefix matches messages based on filenames. This
+option filters filenames of the matching messages.
+.RE
+
 .SH EXIT STATUS
 
 This command supports the following special exit status codes
-- 
1.7.10.4

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

* Re: [PATCH v2 3/7] man: document notmuch search --duplicate=N
  2013-06-09 13:25     ` Mark Walters
@ 2013-06-10 16:39       ` Jani Nikula
  0 siblings, 0 replies; 16+ messages in thread
From: Jani Nikula @ 2013-06-10 16:39 UTC (permalink / raw)
  To: Mark Walters, notmuch

On Sun, 09 Jun 2013, Mark Walters <markwalters1009@gmail.com> wrote:
> Sorry about that: I meant to cancel the message rather than sending it.
>
> What I was wondering was whether we should change the wording of the
> manpage to make it clear that notmuch search --output=files returns all
> filenames where any of the copies matches the search terms (I think; I
> was going to check before sending anything). In particular, 
>
> notmuch search --output=files folder:a_folder may return filenames not
> in a_folder
>
> (This is slightly more noticeable with this patch than before as 
> notmuch search --output=files --duplicate=1 folder:a_folder could give
> no results in folder a_folder
>
> (None of the above is meant to be a criticism of this patch: I have
> only sent this email due to my accidental sending of the previous message)

No worries, it's a valid point. I tried to address them in the updated
man page for --duplicate=N [1], and in an update to the search terms man
page [2].

BR,
Jani.

[1] id:1370881714-3303-1-git-send-email-jani@nikula.org
[2] id:1370881897-3386-1-git-send-email-jani@nikula.org


>
> Best wishes
>
> Mark
>
>
>
>
> What IOn Sun, 09 Jun 2013, Mark Walters <markwalters1009@gmail.com> wrote:
>> One thing that slightly bothers me with this set (which in some sense is
>> already true) is doing a search of the form
>>
>> notmuch search --output=files folder:<a_folder>
>>
>> T
>>
>> On Sun, 09 Jun 2013, Jani Nikula <jani@nikula.org> wrote:
>>> ---
>>>  man/man1/notmuch-search.1 |   11 +++++++++++
>>>  1 file changed, 11 insertions(+)
>>>
>>> diff --git a/man/man1/notmuch-search.1 b/man/man1/notmuch-search.1
>>> index 1c1e049..4d8b3d3 100644
>>> --- a/man/man1/notmuch-search.1
>>> +++ b/man/man1/notmuch-search.1
>>> @@ -158,6 +158,17 @@ but the "match count" is the number of matching non-excluded messages in the
>>>  thread, rather than the number of matching messages.
>>>  .RE
>>>  
>>> +.RS 4
>>> +.TP 4
>>> +.BR \-\-duplicate=N
>>> +
>>> +Effective with
>>> +.BR --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.
>>> +.RE
>>> +
>>>  .SH EXIT STATUS
>>>  
>>>  This command supports the following special exit status codes
>>> -- 
>>> 1.7.10.4
>>>
>>> _______________________________________________
>>> notmuch mailing list
>>> notmuch@notmuchmail.org
>>> http://notmuchmail.org/mailman/listinfo/notmuch

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

* Re: [PATCH v2 1/7] cli: add --duplicate=N option to notmuch search
  2013-06-09 20:22   ` Mark Walters
@ 2013-06-10 16:49     ` Jani Nikula
  0 siblings, 0 replies; 16+ messages in thread
From: Jani Nikula @ 2013-06-10 16:49 UTC (permalink / raw)
  To: Mark Walters, notmuch

On Sun, 09 Jun 2013, Mark Walters <markwalters1009@gmail.com> wrote:
> Overall I like this series and am happy to give it a +1 as is but have a
> few comments which might be worth considering.
>
> Is the order of filenames clear? eg is it the order that notmuch new met
> them? In particular is duplicate=1 the oldest and duplicate=N the
> newest? If so that might be worth mentioning in the manpage.

AFAICT it's the order in which notmuch new encountered them. Which may
change if the user rebuilds the database. Which is why I intentionally
avoided making any promises about what the numbers mean.

>
> On Sun, 09 Jun 2013, Jani Nikula <jani@nikula.org> wrote:
>> Effective with --output=files, output the Nth filename associated with
>> each message matching the query (N is 0-based). If N is equal to or
>> greater than the number of files associated with the message, don't
>> print anything.
>> ---
>>  notmuch-search.c |   18 ++++++++++++------
>>  1 file changed, 12 insertions(+), 6 deletions(-)
>>
>> diff --git a/notmuch-search.c b/notmuch-search.c
>> index 4323201..196934b 100644
>> --- a/notmuch-search.c
>> +++ b/notmuch-search.c
>> @@ -177,7 +177,8 @@ do_search_messages (sprinter_t *format,
>>  		    notmuch_query_t *query,
>>  		    output_t output,
>>  		    int offset,
>> -		    int limit)
>> +		    int limit,
>> +		    int dupe)
>>  {
>>      notmuch_message_t *message;
>>      notmuch_messages_t *messages;
>> @@ -206,14 +207,17 @@ do_search_messages (sprinter_t *format,
>>  	message = notmuch_messages_get (messages);
>>  
>>  	if (output == OUTPUT_FILES) {
>> +	    int j;
>>  	    filenames = notmuch_message_get_filenames (message);
>>  
>> -	    for (;
>> +	    for (j = 1;
>>  		 notmuch_filenames_valid (filenames);
>> -		 notmuch_filenames_move_to_next (filenames))
>> +		 notmuch_filenames_move_to_next (filenames), j++)
>>  	    {
>> -		format->string (format, notmuch_filenames_get (filenames));
>> -		format->separator (format);
>> +		if (dupe < 0 || dupe == j) {
>> +		    format->string (format, notmuch_filenames_get (filenames));
>> +		    format->separator (format);
>
> Is it deliberate that dupe == 0 is not covered? If my newest oldest
> thing above is correct then maybe dupe == 0 could be the all option +N
> the Nth oldest and -N the Nth newest. This may be not-trivial enough
> it's not worth doing.

See my answer above. We can do this later if we decide it's worth the
trouble.

I don't check for 0 because it doesn't match anything. Similarly for
values < 0.

>
>> +		}
>>  	    }
>>  	    
>>  	    notmuch_filenames_destroy( filenames );
>> @@ -303,6 +307,7 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])
>>      int offset = 0;
>>      int limit = -1; /* unlimited */
>>      int exclude = EXCLUDE_TRUE;
>> +    int dupe = -1;
>>      unsigned int i;
>>  
>>      enum {
>> @@ -339,6 +344,7 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])
>>                                    { 0, 0 } } },
>>  	{ NOTMUCH_OPT_INT, &offset, "offset", 'O', 0 },
>>  	{ NOTMUCH_OPT_INT, &limit, "limit", 'L', 0  },
>> +	{ NOTMUCH_OPT_INT, &dupe, "duplicate", 'D', 0  },
>>  	{ 0, 0, 0, 0, 0 }
>>      };
>>  
>> @@ -424,7 +430,7 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])
>>  	break;
>>      case OUTPUT_MESSAGES:
>>      case OUTPUT_FILES:
>> -	ret = do_search_messages (format, query, output, offset, limit);
>> +	ret = do_search_messages (format, query, output, offset, limit, dupe);
>
> Should there be an error message if duplicate=x is chosen with
> output!=files?

I avoided adding checks upon checks, complicating the code, because
there's no harm in allowing it. Matter of taste I suppose.

Thanks for your comments.

BR,
Jani.


>
> Best wishes
>
> Mark
>
>
>>  	break;
>>      case OUTPUT_TAGS:
>>  	ret = do_search_tags (notmuch, format, query);
>> -- 
>> 1.7.10.4
>>
>> _______________________________________________
>> notmuch mailing list
>> notmuch@notmuchmail.org
>> http://notmuchmail.org/mailman/listinfo/notmuch

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

end of thread, other threads:[~2013-06-10 16:49 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-06-09 11:03 [PATCH v2 0/7] cli: better tooling support for duplicate messages Jani Nikula
2013-06-09 11:03 ` [PATCH v2 1/7] cli: add --duplicate=N option to notmuch search Jani Nikula
2013-06-09 20:22   ` Mark Walters
2013-06-10 16:49     ` Jani Nikula
2013-06-10 15:57   ` [PATCH v3] " Jani Nikula
2013-06-09 11:03 ` [PATCH v2 2/7] test: test notmuch search --duplicate=N Jani Nikula
2013-06-09 11:03 ` [PATCH v2 3/7] man: document " Jani Nikula
2013-06-09 13:20   ` Mark Walters
2013-06-09 13:25     ` Mark Walters
2013-06-10 16:39       ` Jani Nikula
2013-06-10 16:28   ` [PATCH v3] " Jani Nikula
2013-06-09 11:03 ` [PATCH v2 4/7] cli: add --output=files option to notmuch count Jani Nikula
2013-06-09 11:03 ` [PATCH v2 5/7] test: test notmuch count --output=files Jani Nikula
2013-06-09 11:03 ` [PATCH v2 6/7] man: document " Jani Nikula
2013-06-09 11:03 ` [PATCH v2 7/7] NEWS: cli options for improved duplicate message handling Jani Nikula
2013-06-10 15:30 ` [PATCH v2 0/7] cli: better tooling support for duplicate 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).