* [PATCH v4 1/5] sprinter: clarify separator documentation
2012-12-16 22:05 [PATCH v4 0/5] add --format=text0 to notmuch search Jani Nikula
@ 2012-12-16 22:05 ` Jani Nikula
2012-12-16 22:05 ` [PATCH v4 2/5] sprinter: add text0 formatter for null character separated text Jani Nikula
` (5 subsequent siblings)
6 siblings, 0 replies; 9+ messages in thread
From: Jani Nikula @ 2012-12-16 22:05 UTC (permalink / raw)
To: notmuch
For text printers, the separator is a syntactic element.
---
sprinter.h | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/sprinter.h b/sprinter.h
index 59776a9..f43a844 100644
--- a/sprinter.h
+++ b/sprinter.h
@@ -42,10 +42,11 @@ typedef struct sprinter {
*/
void (*map_key) (struct sprinter *, const char *);
- /* Insert a separator (usually extra whitespace) for improved
- * readability without affecting the abstract syntax of the
- * structure being printed.
- * For JSON, this could simply be a line break.
+ /* Insert a separator (usually extra whitespace). For the text
+ * printers, this is a syntactic separator. For the structured
+ * printers, this is for improved readability without affecting
+ * the abstract syntax of the structure being printed. For JSON,
+ * this could simply be a line break.
*/
void (*separator) (struct sprinter *);
--
1.7.10.4
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v4 2/5] sprinter: add text0 formatter for null character separated text
2012-12-16 22:05 [PATCH v4 0/5] add --format=text0 to notmuch search Jani Nikula
2012-12-16 22:05 ` [PATCH v4 1/5] sprinter: clarify separator documentation Jani Nikula
@ 2012-12-16 22:05 ` Jani Nikula
2012-12-16 22:05 ` [PATCH v4 3/5] cli: add --format=text0 to notmuch search Jani Nikula
` (4 subsequent siblings)
6 siblings, 0 replies; 9+ messages in thread
From: Jani Nikula @ 2012-12-16 22:05 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 f43a844..f859672 100644
--- a/sprinter.h
+++ b/sprinter.h
@@ -67,6 +67,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] 9+ messages in thread
* [PATCH v4 3/5] cli: add --format=text0 to notmuch search
2012-12-16 22:05 [PATCH v4 0/5] add --format=text0 to notmuch search Jani Nikula
2012-12-16 22:05 ` [PATCH v4 1/5] sprinter: clarify separator documentation Jani Nikula
2012-12-16 22:05 ` [PATCH v4 2/5] sprinter: add text0 formatter for null character separated text Jani Nikula
@ 2012-12-16 22:05 ` Jani Nikula
2012-12-16 22:05 ` [PATCH v4 4/5] test: notmuch search --format=text0 Jani Nikula
` (3 subsequent siblings)
6 siblings, 0 replies; 9+ messages in thread
From: Jani Nikula @ 2012-12-16 22:05 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 7704915..0b0a879 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_INT, ¬much_format_version, "format-version", 0, 0 },
{ NOTMUCH_OPT_KEYWORD, &output, "output", 'o',
@@ -346,6 +351,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] 9+ messages in thread
* [PATCH v4 4/5] test: notmuch search --format=text0
2012-12-16 22:05 [PATCH v4 0/5] add --format=text0 to notmuch search Jani Nikula
` (2 preceding siblings ...)
2012-12-16 22:05 ` [PATCH v4 3/5] cli: add --format=text0 to notmuch search Jani Nikula
@ 2012-12-16 22:05 ` Jani Nikula
2012-12-16 22:05 ` [PATCH v4 5/5] man: document " Jani Nikula
` (2 subsequent siblings)
6 siblings, 0 replies; 9+ messages in thread
From: Jani Nikula @ 2012-12-16 22:05 UTC (permalink / raw)
To: notmuch
---
test/text | 33 +++++++++++++++++++++++++++++++++
1 file changed, 33 insertions(+)
diff --git a/test/text b/test/text
index 428c89b..b5ccefc 100755
--- a/test/text
+++ b/test/text
@@ -52,4 +52,37 @@ 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
+attachment inbox signed unread
+EOF
+notmuch search --format=text0 --output=tags '*' | xargs -0 | notmuch_search_sanitize > OUTPUT
+test_expect_equal_file EXPECTED OUTPUT
+
+# Use tr(1) to convert --output=text0 to --output=text for
+# comparison. Also translate newlines to spaces to fail with more
+# noise if they are present as delimiters instead of null
+# characters. This assumes there are no newlines in the data.
+test_begin_subtest "Compare text vs. text0 for threads"
+notmuch search --format=text --output=threads '*' | notmuch_search_sanitize > EXPECTED
+notmuch search --format=text0 --output=threads '*' | tr "\n\0" " \n" | notmuch_search_sanitize > OUTPUT
+test_expect_equal_file EXPECTED OUTPUT
+
+test_begin_subtest "Compare text vs. text0 for messages"
+notmuch search --format=text --output=messages '*' | notmuch_search_sanitize > EXPECTED
+notmuch search --format=text0 --output=messages '*' | tr "\n\0" " \n" | notmuch_search_sanitize > OUTPUT
+test_expect_equal_file EXPECTED OUTPUT
+
+test_begin_subtest "Compare text vs. text0 for files"
+notmuch search --format=text --output=files '*' | notmuch_search_sanitize > EXPECTED
+notmuch search --format=text0 --output=files '*' | tr "\n\0" " \n" | notmuch_search_sanitize > OUTPUT
+test_expect_equal_file EXPECTED OUTPUT
+
+test_begin_subtest "Compare text vs. text0 for tags"
+notmuch search --format=text --output=tags '*' | notmuch_search_sanitize > EXPECTED
+notmuch search --format=text0 --output=tags '*' | tr "\n\0" " \n" | notmuch_search_sanitize > OUTPUT
+test_expect_equal_file EXPECTED OUTPUT
+
test_done
--
1.7.10.4
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v4 5/5] man: document notmuch search --format=text0
2012-12-16 22:05 [PATCH v4 0/5] add --format=text0 to notmuch search Jani Nikula
` (3 preceding siblings ...)
2012-12-16 22:05 ` [PATCH v4 4/5] test: notmuch search --format=text0 Jani Nikula
@ 2012-12-16 22:05 ` Jani Nikula
2012-12-17 1:06 ` [PATCH v4 0/5] add --format=text0 to notmuch search Tomi Ollila
2012-12-18 21:07 ` David Bremner
6 siblings, 0 replies; 9+ messages in thread
From: Jani Nikula @ 2012-12-16 22:05 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 5c771fa..12f6719 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
@@ -57,32 +59,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] 9+ messages in thread
* Re: [PATCH v4 0/5] add --format=text0 to notmuch search
2012-12-16 22:05 [PATCH v4 0/5] add --format=text0 to notmuch search Jani Nikula
` (4 preceding siblings ...)
2012-12-16 22:05 ` [PATCH v4 5/5] man: document " Jani Nikula
@ 2012-12-17 1:06 ` Tomi Ollila
2012-12-17 1:09 ` Tomi Ollila
2012-12-18 21:07 ` David Bremner
6 siblings, 1 reply; 9+ messages in thread
From: Tomi Ollila @ 2012-12-17 1:06 UTC (permalink / raw)
To: Jani Nikula, notmuch
On Mon, Dec 17 2012, Jani Nikula <jani@nikula.org> wrote:
> Hi all, a quick rebase of id:cover.1355691124.git.jani@nikula.org to fix
> a tiny conflict in patch context of 3/5.
>
> BR,
> Jani.
As Mark & Austin (also) gave +1 to v3 added notmuch::patch (only).
Tomi
>
> Jani Nikula (5):
> sprinter: clarify separator documentation
> 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 | 15 +++++++++++----
> test/text | 33 +++++++++++++++++++++++++++++++++
> 5 files changed, 96 insertions(+), 16 deletions(-)
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v4 0/5] add --format=text0 to notmuch search
2012-12-17 1:06 ` [PATCH v4 0/5] add --format=text0 to notmuch search Tomi Ollila
@ 2012-12-17 1:09 ` Tomi Ollila
0 siblings, 0 replies; 9+ messages in thread
From: Tomi Ollila @ 2012-12-17 1:09 UTC (permalink / raw)
To: Jani Nikula, notmuch
On Mon, Dec 17 2012, Tomi Ollila <tomi.ollila@iki.fi> wrote:
> On Mon, Dec 17 2012, Jani Nikula <jani@nikula.org> wrote:
>
>> Hi all, a quick rebase of id:cover.1355691124.git.jani@nikula.org to fix
>> a tiny conflict in patch context of 3/5.
>>
>> BR,
>> Jani.
>
> As Mark & Austin (also) gave +1 to v3 added notmuch::patch (only).
Ok, it was like that already, my nmbug tree was out-of-sync
(had to fix it with nmbug checkout; nmbug pull)...
> Tomi
Tomi
>>
>> Jani Nikula (5):
>> sprinter: clarify separator documentation
>> 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 | 15 +++++++++++----
>> test/text | 33 +++++++++++++++++++++++++++++++++
>> 5 files changed, 96 insertions(+), 16 deletions(-)
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v4 0/5] add --format=text0 to notmuch search
2012-12-16 22:05 [PATCH v4 0/5] add --format=text0 to notmuch search Jani Nikula
` (5 preceding siblings ...)
2012-12-17 1:06 ` [PATCH v4 0/5] add --format=text0 to notmuch search Tomi Ollila
@ 2012-12-18 21:07 ` David Bremner
6 siblings, 0 replies; 9+ messages in thread
From: David Bremner @ 2012-12-18 21:07 UTC (permalink / raw)
To: Jani Nikula, notmuch
Jani Nikula <jani@nikula.org> writes:
> Hi all, a quick rebase of id:cover.1355691124.git.jani@nikula.org to fix
> a tiny conflict in patch context of 3/5.
>
pushed,
d
^ permalink raw reply [flat|nested] 9+ messages in thread