* [PATCH v2 1/4] sprinter: add text0 formatter for null character separated text
2012-12-09 14:55 [PATCH v2 0/4] cli: add notmuch search --format=text0 Jani Nikula
@ 2012-12-09 14:55 ` Jani Nikula
2012-12-09 14:55 ` [PATCH v2 2/4] cli: add --format=text0 to notmuch search Jani Nikula
` (3 subsequent siblings)
4 siblings, 0 replies; 8+ messages in thread
From: Jani Nikula @ 2012-12-09 14:55 UTC (permalink / raw)
To: notmuch
Same as the text formatter, but with each field separated by a null
character rather than a newline character.
---
sprinter-text.c | 22 ++++++++++++++++++++++
sprinter.h | 6 ++++++
2 files changed, 28 insertions(+)
diff --git a/sprinter-text.c b/sprinter-text.c
index 10343be..7779488 100644
--- a/sprinter-text.c
+++ b/sprinter-text.c
@@ -68,6 +68,14 @@ text_separator (struct sprinter *sp)
}
static void
+text0_separator (struct sprinter *sp)
+{
+ struct sprinter_text *sptxt = (struct sprinter_text *) sp;
+
+ fputc ('\0', sptxt->stream);
+}
+
+static void
text_set_prefix (struct sprinter *sp, const char *prefix)
{
struct sprinter_text *sptxt = (struct sprinter_text *) sp;
@@ -133,3 +141,17 @@ sprinter_text_create (const void *ctx, FILE *stream)
res->stream = stream;
return &res->vtable;
}
+
+struct sprinter *
+sprinter_text0_create (const void *ctx, FILE *stream)
+{
+ struct sprinter *sp;
+
+ sp = sprinter_text_create (ctx, stream);
+ if (! sp)
+ return NULL;
+
+ sp->separator = text0_separator;
+
+ return sp;
+}
diff --git a/sprinter.h b/sprinter.h
index 59776a9..f36b999 100644
--- a/sprinter.h
+++ b/sprinter.h
@@ -66,6 +66,12 @@ typedef struct sprinter {
struct sprinter *
sprinter_text_create (const void *ctx, FILE *stream);
+/* Create a new unstructured printer that emits the text format for
+ * "notmuch search", with each field separated by a null character
+ * instead of the newline character. */
+struct sprinter *
+sprinter_text0_create (const void *ctx, FILE *stream);
+
/* Create a new structure printer that emits JSON. */
struct sprinter *
sprinter_json_create (const void *ctx, FILE *stream);
--
1.7.10.4
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v2 2/4] cli: add --format=text0 to notmuch search
2012-12-09 14:55 [PATCH v2 0/4] cli: add notmuch search --format=text0 Jani Nikula
2012-12-09 14:55 ` [PATCH v2 1/4] sprinter: add text0 formatter for null character separated text Jani Nikula
@ 2012-12-09 14:55 ` Jani Nikula
2012-12-09 14:55 ` [PATCH v2 3/4] test: notmuch search --format=text0 Jani Nikula
` (2 subsequent siblings)
4 siblings, 0 replies; 8+ messages in thread
From: Jani Nikula @ 2012-12-09 14:55 UTC (permalink / raw)
To: notmuch
Add new format text0, which is otherwise the same as text, but use the
null character as separator instead of the newline character. This is
similar to find(1) -print0 option, and works together with the
xargs(1) -0 option.
---
notmuch-search.c | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)
diff --git a/notmuch-search.c b/notmuch-search.c
index 6218622..627962b 100644
--- a/notmuch-search.c
+++ b/notmuch-search.c
@@ -305,8 +305,12 @@ notmuch_search_command (void *ctx, int argc, char *argv[])
int exclude = EXCLUDE_TRUE;
unsigned int i;
- enum { NOTMUCH_FORMAT_JSON, NOTMUCH_FORMAT_TEXT, NOTMUCH_FORMAT_SEXP }
- format_sel = NOTMUCH_FORMAT_TEXT;
+ enum {
+ NOTMUCH_FORMAT_JSON,
+ NOTMUCH_FORMAT_TEXT,
+ NOTMUCH_FORMAT_TEXT0,
+ NOTMUCH_FORMAT_SEXP
+ } format_sel = NOTMUCH_FORMAT_TEXT;
notmuch_opt_desc_t options[] = {
{ NOTMUCH_OPT_KEYWORD, &sort, "sort", 's',
@@ -317,6 +321,7 @@ notmuch_search_command (void *ctx, int argc, char *argv[])
(notmuch_keyword_t []){ { "json", NOTMUCH_FORMAT_JSON },
{ "sexp", NOTMUCH_FORMAT_SEXP },
{ "text", NOTMUCH_FORMAT_TEXT },
+ { "text0", NOTMUCH_FORMAT_TEXT0 },
{ 0, 0 } } },
{ NOTMUCH_OPT_KEYWORD, &output, "output", 'o',
(notmuch_keyword_t []){ { "summary", OUTPUT_SUMMARY },
@@ -345,6 +350,13 @@ notmuch_search_command (void *ctx, int argc, char *argv[])
case NOTMUCH_FORMAT_TEXT:
format = sprinter_text_create (ctx, stdout);
break;
+ case NOTMUCH_FORMAT_TEXT0:
+ if (output == OUTPUT_SUMMARY) {
+ fprintf (stderr, "Error: --format=text0 is not compatible with --output=summary.\n");
+ return 1;
+ }
+ format = sprinter_text0_create (ctx, stdout);
+ break;
case NOTMUCH_FORMAT_JSON:
format = sprinter_json_create (ctx, stdout);
break;
--
1.7.10.4
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v2 3/4] test: notmuch search --format=text0
2012-12-09 14:55 [PATCH v2 0/4] cli: add notmuch search --format=text0 Jani Nikula
2012-12-09 14:55 ` [PATCH v2 1/4] sprinter: add text0 formatter for null character separated text Jani Nikula
2012-12-09 14:55 ` [PATCH v2 2/4] cli: add --format=text0 to notmuch search Jani Nikula
@ 2012-12-09 14:55 ` Jani Nikula
2012-12-16 8:17 ` Mark Walters
2012-12-16 15:51 ` Austin Clements
2012-12-09 14:55 ` [PATCH v2 4/4] man: document " Jani Nikula
2012-12-09 15:51 ` [PATCH v2 0/4] cli: add " Mark Walters
4 siblings, 2 replies; 8+ messages in thread
From: Jani Nikula @ 2012-12-09 14:55 UTC (permalink / raw)
To: notmuch
---
test/text | 29 +++++++++++++++++++++++++++++
1 file changed, 29 insertions(+)
diff --git a/test/text b/test/text
index 428c89b..e003a66 100755
--- a/test/text
+++ b/test/text
@@ -52,4 +52,33 @@ output=$(notmuch search --format=text "tëxt-search-méssage" | notmuch_search_s
test_expect_equal "$output" \
"thread:XXX 2000-01-01 [1/1] Notmuch Test Suite; text-search-utf8-body-sübjéct (inbox unread)"
+add_email_corpus
+
+test_begin_subtest "Search message tags: text0"
+cat <<EOF > EXPECTED.$test_count
+attachment inbox signed unread
+EOF
+notmuch search --format=text0 --output=tags '*' | xargs -0 | notmuch_search_sanitize > OUTPUT.$test_count
+test_expect_equal_file EXPECTED.$test_count OUTPUT.$test_count
+
+test_begin_subtest "Compare text vs. text0 for threads"
+notmuch search --format=text --output=threads '*' | notmuch_search_sanitize > EXPECTED.$test_count
+notmuch search --format=text0 --output=threads '*' | xargs -0 -L1 | notmuch_search_sanitize > OUTPUT.$test_count
+test_expect_equal_file EXPECTED.$test_count OUTPUT.$test_count
+
+test_begin_subtest "Compare text vs. text0 for messages"
+notmuch search --format=text --output=messages '*' | notmuch_search_sanitize > EXPECTED.$test_count
+notmuch search --format=text0 --output=messages '*' | xargs -0 -L1 | notmuch_search_sanitize > OUTPUT.$test_count
+test_expect_equal_file EXPECTED.$test_count OUTPUT.$test_count
+
+test_begin_subtest "Compare text vs. text0 for files"
+notmuch search --format=text --output=files '*' | notmuch_search_sanitize > EXPECTED.$test_count
+notmuch search --format=text0 --output=files '*' | xargs -0 -L1 | notmuch_search_sanitize > OUTPUT.$test_count
+test_expect_equal_file EXPECTED.$test_count OUTPUT.$test_count
+
+test_begin_subtest "Compare text vs. text0 for tags"
+notmuch search --format=text --output=tags '*' | notmuch_search_sanitize > EXPECTED.$test_count
+notmuch search --format=text0 --output=tags '*' | xargs -0 -L1 | notmuch_search_sanitize > OUTPUT.$test_count
+test_expect_equal_file EXPECTED.$test_count OUTPUT.$test_count
+
test_done
--
1.7.10.4
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH v2 3/4] test: notmuch search --format=text0
2012-12-09 14:55 ` [PATCH v2 3/4] test: notmuch search --format=text0 Jani Nikula
@ 2012-12-16 8:17 ` Mark Walters
2012-12-16 15:51 ` Austin Clements
1 sibling, 0 replies; 8+ messages in thread
From: Mark Walters @ 2012-12-16 8:17 UTC (permalink / raw)
To: Jani Nikula, notmuch
On Sun, 09 Dec 2012, Jani Nikula <jani@nikula.org> wrote:
> ---
> test/text | 29 +++++++++++++++++++++++++++++
> 1 file changed, 29 insertions(+)
>
> diff --git a/test/text b/test/text
> index 428c89b..e003a66 100755
> --- a/test/text
> +++ b/test/text
> @@ -52,4 +52,33 @@ output=$(notmuch search --format=text "tëxt-search-méssage" | notmuch_search_s
> test_expect_equal "$output" \
> "thread:XXX 2000-01-01 [1/1] Notmuch Test Suite; text-search-utf8-body-sübjéct (inbox unread)"
>
> +add_email_corpus
> +
> +test_begin_subtest "Search message tags: text0"
> +cat <<EOF > EXPECTED.$test_count
> +attachment inbox signed unread
> +EOF
> +notmuch search --format=text0 --output=tags '*' | xargs -0 | notmuch_search_sanitize > OUTPUT.$test_count
> +test_expect_equal_file EXPECTED.$test_count OUTPUT.$test_count
> +
> +test_begin_subtest "Compare text vs. text0 for threads"
> +notmuch search --format=text --output=threads '*' | notmuch_search_sanitize > EXPECTED.$test_count
> +notmuch search --format=text0 --output=threads '*' | xargs -0 -L1 | notmuch_search_sanitize > OUTPUT.$test_count
> +test_expect_equal_file EXPECTED.$test_count OUTPUT.$test_count
Hi
These xargs -0 -L1 tests almost pass with format=text (no zero) passed:
the output only differs in one newline at the end. Would it be worth
strengthening the test at all? I don't have any good suggestion but
replacing the xargs with
tr '\n\0' ' \n'
seemed to give clearly different output in the two cases (and the test
passes as it stands).
OTOH maybe the test before is sufficient in that respect.
Best wishes
Mark
> +
> +test_begin_subtest "Compare text vs. text0 for messages"
> +notmuch search --format=text --output=messages '*' | notmuch_search_sanitize > EXPECTED.$test_count
> +notmuch search --format=text0 --output=messages '*' | xargs -0 -L1 | notmuch_search_sanitize > OUTPUT.$test_count
> +test_expect_equal_file EXPECTED.$test_count OUTPUT.$test_count
> +
> +test_begin_subtest "Compare text vs. text0 for files"
> +notmuch search --format=text --output=files '*' | notmuch_search_sanitize > EXPECTED.$test_count
> +notmuch search --format=text0 --output=files '*' | xargs -0 -L1 | notmuch_search_sanitize > OUTPUT.$test_count
> +test_expect_equal_file EXPECTED.$test_count OUTPUT.$test_count
> +
> +test_begin_subtest "Compare text vs. text0 for tags"
> +notmuch search --format=text --output=tags '*' | notmuch_search_sanitize > EXPECTED.$test_count
> +notmuch search --format=text0 --output=tags '*' | xargs -0 -L1 | notmuch_search_sanitize > OUTPUT.$test_count
> +test_expect_equal_file EXPECTED.$test_count OUTPUT.$test_count
> +
> test_done
> --
> 1.7.10.4
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2 3/4] test: notmuch search --format=text0
2012-12-09 14:55 ` [PATCH v2 3/4] test: notmuch search --format=text0 Jani Nikula
2012-12-16 8:17 ` Mark Walters
@ 2012-12-16 15:51 ` Austin Clements
1 sibling, 0 replies; 8+ messages in thread
From: Austin Clements @ 2012-12-16 15:51 UTC (permalink / raw)
To: Jani Nikula, notmuch
On Sun, 09 Dec 2012, Jani Nikula <jani@nikula.org> wrote:
> ---
> test/text | 29 +++++++++++++++++++++++++++++
> 1 file changed, 29 insertions(+)
>
> diff --git a/test/text b/test/text
> index 428c89b..e003a66 100755
> --- a/test/text
> +++ b/test/text
> @@ -52,4 +52,33 @@ output=$(notmuch search --format=text "tëxt-search-méssage" | notmuch_search_s
> test_expect_equal "$output" \
> "thread:XXX 2000-01-01 [1/1] Notmuch Test Suite; text-search-utf8-body-sübjéct (inbox unread)"
>
> +add_email_corpus
> +
> +test_begin_subtest "Search message tags: text0"
> +cat <<EOF > EXPECTED.$test_count
Other tests use just OUTPUT and EXPECTED. Why the $test_count? Is
there a technical reason for it?
> +attachment inbox signed unread
> +EOF
> +notmuch search --format=text0 --output=tags '*' | xargs -0 | notmuch_search_sanitize > OUTPUT.$test_count
> +test_expect_equal_file EXPECTED.$test_count OUTPUT.$test_count
> +
> +test_begin_subtest "Compare text vs. text0 for threads"
> +notmuch search --format=text --output=threads '*' | notmuch_search_sanitize > EXPECTED.$test_count
> +notmuch search --format=text0 --output=threads '*' | xargs -0 -L1 | notmuch_search_sanitize > OUTPUT.$test_count
I think it would be worth "strengthening" these tests as Mark pointed
out. It would be easy to accidentally include a literal \n in the
output instead of calling the separator method, and this test wouldn't
catch that. I think Mark's suggestion with tr is pretty good, since it
directly disambiguates \0 and \n in the output, while producing a
reasonable diff if things do go wrong.
> +test_expect_equal_file EXPECTED.$test_count OUTPUT.$test_count
> +
> +test_begin_subtest "Compare text vs. text0 for messages"
> +notmuch search --format=text --output=messages '*' | notmuch_search_sanitize > EXPECTED.$test_count
> +notmuch search --format=text0 --output=messages '*' | xargs -0 -L1 | notmuch_search_sanitize > OUTPUT.$test_count
> +test_expect_equal_file EXPECTED.$test_count OUTPUT.$test_count
> +
> +test_begin_subtest "Compare text vs. text0 for files"
> +notmuch search --format=text --output=files '*' | notmuch_search_sanitize > EXPECTED.$test_count
> +notmuch search --format=text0 --output=files '*' | xargs -0 -L1 | notmuch_search_sanitize > OUTPUT.$test_count
> +test_expect_equal_file EXPECTED.$test_count OUTPUT.$test_count
> +
> +test_begin_subtest "Compare text vs. text0 for tags"
> +notmuch search --format=text --output=tags '*' | notmuch_search_sanitize > EXPECTED.$test_count
> +notmuch search --format=text0 --output=tags '*' | xargs -0 -L1 | notmuch_search_sanitize > OUTPUT.$test_count
> +test_expect_equal_file EXPECTED.$test_count OUTPUT.$test_count
> +
> test_done
> --
> 1.7.10.4
>
> _______________________________________________
> notmuch mailing list
> notmuch@notmuchmail.org
> http://notmuchmail.org/mailman/listinfo/notmuch
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v2 4/4] man: document notmuch search --format=text0
2012-12-09 14:55 [PATCH v2 0/4] cli: add notmuch search --format=text0 Jani Nikula
` (2 preceding siblings ...)
2012-12-09 14:55 ` [PATCH v2 3/4] test: notmuch search --format=text0 Jani Nikula
@ 2012-12-09 14:55 ` Jani Nikula
2012-12-09 15:51 ` [PATCH v2 0/4] cli: add " Mark Walters
4 siblings, 0 replies; 8+ messages in thread
From: Jani Nikula @ 2012-12-09 14:55 UTC (permalink / raw)
To: notmuch
---
man/man1/notmuch-search.1 | 26 ++++++++++++++++----------
1 file changed, 16 insertions(+), 10 deletions(-)
diff --git a/man/man1/notmuch-search.1 b/man/man1/notmuch-search.1
index 0aff348..22bcd0a 100644
--- a/man/man1/notmuch-search.1
+++ b/man/man1/notmuch-search.1
@@ -25,9 +25,11 @@ Supported options for
include
.RS 4
.TP 4
-.BR \-\-format= ( json | sexp | text )
+.BR \-\-format= ( json | sexp | text | text0 )
-Presents the results in either JSON, S-Expressions or plain-text (default).
+Presents the results in either JSON, S-Expressions, newline character
+separated plain-text (default), or null character separated plain-text
+(compatible with \fBxargs\fR(1) -0 option where available).
.RE
.RS 4
@@ -48,32 +50,36 @@ the authors of the thread and the subject.
.B threads
Output the thread IDs of all threads with any message matching the
-search terms, either one per line (\-\-format=text) or as a JSON array
-(\-\-format=json) or an S-Expression list (\-\-format=sexp).
+search terms, either one per line (\-\-format=text), separated by null
+characters (\-\-format=text0), as a JSON array (\-\-format=json), or
+an S-Expression list (\-\-format=sexp).
.RE
.RS 4
.TP 4
.B messages
Output the message IDs of all messages matching the search terms,
-either one per line (\-\-format=text) or as a JSON array
-(\-\-format=json) or as an S-Expression list (\-\-format=sexp).
+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).
.RE
.RS 4
.TP 4
.B files
Output the filenames of all messages matching the search terms, either
-one per line (\-\-format=text) or as a JSON array (\-\-format=json) or
-as an S-Expression list (\-\-format=sexp).
+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).
.RE
.RS 4
.TP 4
.B tags
Output all tags that appear on any message matching the search terms,
-either one per line (\-\-format=text) or as a JSON array (\-\-format=json)
-or as an S-Expression list (\-\-format=sexp).
+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).
.RE
.RE
--
1.7.10.4
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH v2 0/4] cli: add notmuch search --format=text0
2012-12-09 14:55 [PATCH v2 0/4] cli: add notmuch search --format=text0 Jani Nikula
` (3 preceding siblings ...)
2012-12-09 14:55 ` [PATCH v2 4/4] man: document " Jani Nikula
@ 2012-12-09 15:51 ` Mark Walters
4 siblings, 0 replies; 8+ messages in thread
From: Mark Walters @ 2012-12-09 15:51 UTC (permalink / raw)
To: Jani Nikula, notmuch
This looks good to me.
+1
Mark
On Sun, 09 Dec 2012, Jani Nikula <jani@nikula.org> wrote:
> This is v2 of [1], with a rebase, disallowing --format=text0 --output=summary
> combination per Mark's suggestion, and adding man page and tests.
>
> BR,
> Jani.
>
>
> [1] id:30f03a18ed10c221c13b6672f90654963c76452d.1354832980.git.jani@nikula.org
>
>
> Jani Nikula (4):
> sprinter: add text0 formatter for null character separated text
> cli: add --format=text0 to notmuch search
> test: notmuch search --format=text0
> man: document notmuch search --format=text0
>
> man/man1/notmuch-search.1 | 26 ++++++++++++++++----------
> notmuch-search.c | 16 ++++++++++++++--
> sprinter-text.c | 22 ++++++++++++++++++++++
> sprinter.h | 6 ++++++
> test/text | 29 +++++++++++++++++++++++++++++
> 5 files changed, 87 insertions(+), 12 deletions(-)
>
> --
> 1.7.10.4
^ permalink raw reply [flat|nested] 8+ messages in thread