From: David Bremner Date: Sun, 5 Apr 2015 22:59:11 +0000 (+0900) Subject: [WIP2 09/12] cli/search: add metadata element to structured output X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=a394c94e6acfed18a7ac8841b1b5d5a8782909ec;p=notmuch-archives.git [WIP2 09/12] cli/search: add metadata element to structured output --- diff --git a/13/a6074c16b059e30b4558fd3148773f7dc50c57 b/13/a6074c16b059e30b4558fd3148773f7dc50c57 new file mode 100644 index 000000000..68c73ec22 --- /dev/null +++ b/13/a6074c16b059e30b4558fd3148773f7dc50c57 @@ -0,0 +1,373 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by arlo.cworth.org (Postfix) with ESMTP id C2F896DE1BD3 + for ; Sun, 5 Apr 2015 16:03:56 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at cworth.org +X-Spam-Flag: NO +X-Spam-Score: 0.488 +X-Spam-Level: +X-Spam-Status: No, score=0.488 tagged_above=-999 required=5 tests=[AWL=0.478, + T_HEADER_FROM_DIFFERENT_DOMAINS=0.01] autolearn=disabled +Received: from arlo.cworth.org ([127.0.0.1]) + by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id SVGGayr289jQ for ; + Sun, 5 Apr 2015 16:03:54 -0700 (PDT) +Received: from mx.xen14.node3324.gplhost.com (gitolite.debian.net + [87.98.215.224]) + by arlo.cworth.org (Postfix) with ESMTPS id 5AA656DE1BD5 + for ; Sun, 5 Apr 2015 16:03:53 -0700 (PDT) +Received: from remotemail by mx.xen14.node3324.gplhost.com with local (Exim + 4.80) (envelope-from ) + id 1YetZP-0002rI-R0; Sun, 05 Apr 2015 23:03:11 +0000 +Received: (nullmailer pid 2253 invoked by uid 1000); Sun, 05 Apr 2015 + 22:59:25 -0000 +From: David Bremner +To: notmuch@notmuchmail.org +Subject: [WIP2 09/12] cli/search: add metadata element to structured output +Date: Mon, 6 Apr 2015 07:59:11 +0900 +Message-Id: <1428274754-1698-10-git-send-email-david@tethera.net> +X-Mailer: git-send-email 2.1.4 +In-Reply-To: <1428274754-1698-1-git-send-email-david@tethera.net> +References: <1428274754-1698-1-git-send-email-david@tethera.net> +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.18 +Precedence: list +List-Id: "Use and development of the notmuch mail system." + +List-Unsubscribe: , + +List-Archive: +List-Post: +List-Help: +List-Subscribe: , + +X-List-Received-Date: Sun, 05 Apr 2015 23:03:56 -0000 + +As before, we force the test suite to use format version 2 in order +not to break. This is probably not the solution for the final version +of these patches. +--- + devel/schemata | 10 +++++----- + notmuch-search.c | 18 +++++++++--------- + test/T070-insert.sh | 2 +- + test/T090-search-output.sh | 20 ++++++++++---------- + test/T095-address.sh | 4 ++-- + test/T160-json.sh | 4 ++-- + test/T170-sexp.sh | 4 ++-- + test/T470-missing-headers.sh | 2 +- + test/test-lib.sh | 8 ++++++++ + 9 files changed, 40 insertions(+), 32 deletions(-) + +diff --git a/devel/schemata b/devel/schemata +index 02f7cc0..e297adf 100644 +--- a/devel/schemata ++++ b/devel/schemata +@@ -144,19 +144,19 @@ notmuch search schema + --------------------- + + # --output=summary +-search_summary = [thread_summary*] ++search_summary = [database_metadata, thread_summary*] + + # --output=threads +-search_threads = [threadid*] ++search_threads = [database_metadata, threadid*] + + # --output=messages +-search_messages = [messageid*] ++search_messages = [database_metadata, messageid*] + + # --output=files +-search_files = [string*] ++search_files = [database_metadata, string*] + + # --output=tags +-search_tags = [string*] ++search_tags = [database_metadata, string*] + + thread_summary = { + database: database_metadata +diff --git a/notmuch-search.c b/notmuch-search.c +index 994ae58..5d17dac 100644 +--- a/notmuch-search.c ++++ b/notmuch-search.c +@@ -122,7 +122,8 @@ do_search_threads (search_context_t *ctx) + if (threads == NULL) + return 1; + +- format->begin_list (format); ++ sprinter_start_output (format, ctx->query, ++ (ctx->output == OUTPUT_THREADS) ? "threads" : "summary"); + + for (i = 0; + notmuch_threads_valid (threads) && (ctx->limit < 0 || i < ctx->offset + ctx->limit); +@@ -238,8 +239,7 @@ do_search_threads (search_context_t *ctx) + notmuch_thread_destroy (thread); + } + +- format->end (format); +- ++ sprinter_finish_output (format); + return 0; + } + +@@ -423,7 +423,7 @@ do_search_messages (search_context_t *ctx) + if (messages == NULL) + return 1; + +- format->begin_list (format); ++ sprinter_start_output (format, ctx->query, "messages"); + + for (i = 0; + notmuch_messages_valid (messages) && (ctx->limit < 0 || i < ctx->offset + ctx->limit); +@@ -486,8 +486,7 @@ do_search_messages (search_context_t *ctx) + + notmuch_messages_destroy (messages); + +- format->end (format); +- ++ sprinter_finish_output (format); + return 0; + } + +@@ -505,6 +504,8 @@ do_search_tags (const search_context_t *ctx) + * specified? */ + + /* Special-case query of "*" for better performance. */ ++ ++ + if (strcmp (notmuch_query_get_query_string (query), "*") == 0) { + tags = notmuch_database_get_all_tags (notmuch); + } else { +@@ -517,7 +518,7 @@ do_search_tags (const search_context_t *ctx) + if (tags == NULL) + return 1; + +- format->begin_list (format); ++ sprinter_start_output (format, query, "tags"); + + for (; + notmuch_tags_valid (tags); +@@ -535,8 +536,7 @@ do_search_tags (const search_context_t *ctx) + if (messages) + notmuch_messages_destroy (messages); + +- format->end (format); +- ++ sprinter_finish_output (format); + return 0; + } + +diff --git a/test/T070-insert.sh b/test/T070-insert.sh +index 48d36af..67acbb0 100755 +--- a/test/T070-insert.sh ++++ b/test/T070-insert.sh +@@ -64,7 +64,7 @@ output=$(notmuch search --output=files "subject:insert-subject" | wc -l) + test_expect_equal "$output" 2 + + test_begin_subtest "Duplicate message does not change tags" +-output=$(notmuch search --format=json --output=tags "subject:insert-subject") ++output=$(NOTMUCH_SEARCH --format=json --output=tags "subject:insert-subject") + test_expect_equal_json "$output" '["inbox", "unread"]' + + test_begin_subtest "Insert message, add tag" +diff --git a/test/T090-search-output.sh b/test/T090-search-output.sh +index fe2ec9a..1dc74b6 100755 +--- a/test/T090-search-output.sh ++++ b/test/T090-search-output.sh +@@ -35,7 +35,7 @@ EOF + test_expect_equal_file OUTPUT EXPECTED + + test_begin_subtest "--output=threads --format=json" +-notmuch search --format=json --output=threads '*' | sed -e s/\".*\"/\"THREADID\"/ >OUTPUT ++NOTMUCH_SEARCH --format=json --output=threads '*' | sed -e s/\".*\"/\"THREADID\"/ >OUTPUT + cat <EXPECTED + ["THREADID", + "THREADID", +@@ -141,7 +141,7 @@ EOF + test_expect_equal_file OUTPUT EXPECTED + + test_begin_subtest "--output=messages --format=json" +-notmuch search --format=json --output=messages '*' >OUTPUT ++NOTMUCH_SEARCH --format=json --output=messages '*' >OUTPUT + cat <EXPECTED + ["4EFC743A.3060609@april.org", + "877h1wv7mg.fsf@inf-8657.int-evry.fr", +@@ -199,19 +199,19 @@ 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 ++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 ++NOTMUCH_SEARCH --output=messages --format=json --duplicate=2 '*' >OUTPUT + cat <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 ++NOTMUCH_SEARCH --output=messages --format=json --duplicate=3 '*' >OUTPUT + cat <EXPECTED + [] + EOF +@@ -338,7 +338,7 @@ EOF + test_expect_equal_file OUTPUT EXPECTED + + test_begin_subtest "--output=files --format=json" +-notmuch search --format=json --output=files '*' | notmuch_search_files_sanitize \ ++NOTMUCH_SEARCH --format=json --output=files '*' | notmuch_search_files_sanitize \ + | test_sort_json >OUTPUT + cat <EXPECTED + ["MAIL_DIR/cur/52:2,", +@@ -398,14 +398,14 @@ EOF + test_expect_equal_file OUTPUT EXPECTED + + test_begin_subtest "--output=files --format=json --duplicate=2" +-notmuch search --format=json --output=files --duplicate=2 '*' | notmuch_search_files_sanitize >OUTPUT ++NOTMUCH_SEARCH --format=json --output=files --duplicate=2 '*' | notmuch_search_files_sanitize >OUTPUT + cat <EXPECTED + ["$dup2"] + EOF + test_expect_equal_file OUTPUT EXPECTED + + test_begin_subtest "--output=tags" +-notmuch search --output=tags '*' >OUTPUT ++NOTMUCH_SEARCH --output=tags '*' >OUTPUT + cat <EXPECTED + attachment + inbox +@@ -415,7 +415,7 @@ EOF + test_expect_equal_file OUTPUT EXPECTED + + test_begin_subtest "--output=tags --format=json" +-notmuch search --format=json --output=tags '*' >OUTPUT ++NOTMUCH_SEARCH --format=json --output=tags '*' >OUTPUT + cat <EXPECTED + ["attachment", + "inbox", +@@ -439,7 +439,7 @@ echo -n >EXPECTED + test_expect_equal_file OUTPUT EXPECTED + + test_begin_subtest "search --format=json for non-existent message prints proper empty json" +-notmuch search --format=json "no-message-matches-this" > OUTPUT ++NOTMUCH_SEARCH --format=json "no-message-matches-this" > OUTPUT + echo "[]" >EXPECTED + test_expect_equal_file OUTPUT EXPECTED + +diff --git a/test/T095-address.sh b/test/T095-address.sh +index ed0cac7..6eae30e 100755 +--- a/test/T095-address.sh ++++ b/test/T095-address.sh +@@ -33,7 +33,7 @@ notmuch address '*' >OUTPUT + test_expect_equal_file OUTPUT EXPECTED + + test_begin_subtest "--output=sender --format=json" +-notmuch address --output=sender --format=json '*' >OUTPUT ++NOTMUCH_ADDRESS --output=sender --format=json '*' >OUTPUT + cat <EXPECTED + [{"name": "François Boulogne", "address": "boulogne.f@gmail.com", "name-addr": "François Boulogne "}, + {"name": "Olivier Berger", "address": "olivier.berger@it-sudparis.eu", "name-addr": "Olivier Berger "}, +@@ -122,7 +122,7 @@ test_expect_equal_file OUTPUT EXPECTED + test_begin_subtest "--output=count --format=json" + # Since the iteration order of GHashTable is not specified, we + # preprocess and sort the results to keep the order stable here. +-notmuch address --output=count --format=json '*' | \ ++NOTMUCH_ADDRESS --output=count --format=json '*' | \ + sed -e 's/^\[//' -e 's/]$//' -e 's/,$//' | sort >OUTPUT + cat <EXPECTED + {"name": "Adrian Perez de Castro", "address": "aperez@igalia.com", "name-addr": "Adrian Perez de Castro ", "count": 1} +diff --git a/test/T160-json.sh b/test/T160-json.sh +index 46c1314..10df42a 100755 +--- a/test/T160-json.sh ++++ b/test/T160-json.sh +@@ -18,7 +18,7 @@ test_expect_equal_json "$output" "[[[{\"id\": \"${gen_msg_id}\", \"match\": true + + test_begin_subtest "Search message: json" + add_message "[subject]=\"json-search-subject\"" "[date]=\"Sat, 01 Jan 2000 12:00:00 -0000\"" "[body]=\"json-search-message\"" +-output=$(notmuch search --format=json "json-search-message" | notmuch_search_sanitize) ++output=$(NOTMUCH_SEARCH --format=json "json-search-message" | notmuch_search_sanitize) + test_expect_equal_json "$output" "[{\"thread\": \"XXX\", + \"timestamp\": 946728000, + \"date_relative\": \"2000-01-01\", +@@ -52,7 +52,7 @@ test_expect_equal_json "$output" "[[[{\"id\": \"$id\", \"match\": true, \"exclud + + test_begin_subtest "Search message: json, utf-8" + add_message "[subject]=\"json-search-utf8-body-sübjéct\"" "[date]=\"Sat, 01 Jan 2000 12:00:00 -0000\"" "[body]=\"jsön-search-méssage\"" +-output=$(notmuch search --format=json "jsön-search-méssage" | notmuch_search_sanitize) ++output=$(NOTMUCH_SEARCH --format=json "jsön-search-méssage" | notmuch_search_sanitize) + test_expect_equal_json "$output" "[{\"thread\": \"XXX\", + \"timestamp\": 946728000, + \"date_relative\": \"2000-01-01\", +diff --git a/test/T170-sexp.sh b/test/T170-sexp.sh +index 6c7402a..06a7f98 100755 +--- a/test/T170-sexp.sh ++++ b/test/T170-sexp.sh +@@ -18,7 +18,7 @@ test_expect_equal "$output" "((((:id \"${gen_msg_id}\" :match t :excluded nil :f + + test_begin_subtest "Search message: sexp" + add_message "[subject]=\"sexp-search-subject\"" "[date]=\"Sat, 01 Jan 2000 12:00:00 -0000\"" "[body]=\"sexp-search-message\"" +-output=$(notmuch search --format=sexp "sexp-search-message" | notmuch_search_sanitize) ++output=$(NOTMUCH_SEARCH --format=sexp "sexp-search-message" | notmuch_search_sanitize) + test_expect_equal "$output" "((:thread \"0000000000000002\" :timestamp 946728000 :date_relative \"2000-01-01\" :matched 1 :total 1 :authors \"Notmuch Test Suite\" :subject \"sexp-search-subject\" :query (\"id:$gen_msg_id\" nil) :tags (\"inbox\" \"unread\")))" + + test_begin_subtest "Show message: sexp, utf-8" +@@ -43,7 +43,7 @@ test_expect_equal "$output" "((((:id \"$id\" :match t :excluded nil :filename \" + + test_begin_subtest "Search message: sexp, utf-8" + add_message "[subject]=\"sexp-search-utf8-body-sübjéct\"" "[date]=\"Sat, 01 Jan 2000 12:00:00 -0000\"" "[body]=\"jsön-search-méssage\"" +-output=$(notmuch search --format=sexp "jsön-search-méssage" | notmuch_search_sanitize) ++output=$(NOTMUCH_SEARCH --format=sexp "jsön-search-méssage" | notmuch_search_sanitize) + test_expect_equal "$output" "((:thread \"0000000000000005\" :timestamp 946728000 :date_relative \"2000-01-01\" :matched 1 :total 1 :authors \"Notmuch Test Suite\" :subject \"sexp-search-utf8-body-sübjéct\" :query (\"id:$gen_msg_id\" nil) :tags (\"inbox\" \"unread\")))" + + +diff --git a/test/T470-missing-headers.sh b/test/T470-missing-headers.sh +index c3ee430..2e24a74 100755 +--- a/test/T470-missing-headers.sh ++++ b/test/T470-missing-headers.sh +@@ -29,7 +29,7 @@ thread:XXX 2001-01-05 [1/1] (null); (inbox unread) + thread:XXX 1970-01-01 [1/1] Notmuch Test Suite; (inbox unread)" + + test_begin_subtest "Search: json" +-output=$(notmuch search --format=json '*' | notmuch_search_sanitize) ++output=$(NOTMUCH_SEARCH --format=json '*' | notmuch_search_sanitize) + test_expect_equal_json "$output" ' + [ + { +diff --git a/test/test-lib.sh b/test/test-lib.sh +index d30608a..d9d8ea1 100644 +--- a/test/test-lib.sh ++++ b/test/test-lib.sh +@@ -664,11 +664,19 @@ test_emacs_expect_t () { + fi + } + ++NOTMUCH_ADDRESS () { ++ notmuch address --format-version=2 "${@}" ++} ++ + NOTMUCH_NEW () + { + notmuch new "${@}" | grep -v -E -e '^Processed [0-9]*( total)? file|Found [0-9]* total file' + } + ++NOTMUCH_SEARCH () { ++ notmuch search --format-version=2 "${@}" ++} ++ + NOTMUCH_SHOW () { + notmuch show --format-version=2 "${@}" + } +-- +2.1.4 +