1 Return-Path: <bremner@tethera.net>
\r
2 X-Original-To: notmuch@notmuchmail.org
\r
3 Delivered-To: notmuch@notmuchmail.org
\r
4 Received: from localhost (localhost [127.0.0.1])
\r
5 by arlo.cworth.org (Postfix) with ESMTP id 560566DE00BD
\r
6 for <notmuch@notmuchmail.org>; Wed, 25 May 2016 03:51:46 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at cworth.org
\r
11 X-Spam-Status: No, score=-0.012 tagged_above=-999 required=5
\r
12 tests=[AWL=-0.001, SPF_PASS=-0.001, T_RP_MATCHES_RCVD=-0.01]
\r
14 Received: from arlo.cworth.org ([127.0.0.1])
\r
15 by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)
\r
16 with ESMTP id HGWtLxXMhwWe for <notmuch@notmuchmail.org>;
\r
17 Wed, 25 May 2016 03:51:37 -0700 (PDT)
\r
18 Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197])
\r
19 by arlo.cworth.org (Postfix) with ESMTPS id C5D656DE0159
\r
20 for <notmuch@notmuchmail.org>; Wed, 25 May 2016 03:51:36 -0700 (PDT)
\r
21 Received: from remotemail by fethera.tethera.net with local (Exim 4.84)
\r
22 (envelope-from <bremner@tethera.net>)
\r
23 id 1b5WPN-0004Tc-HB; Wed, 25 May 2016 06:51:25 -0400
\r
24 Received: (nullmailer pid 23146 invoked by uid 1000);
\r
25 Wed, 25 May 2016 10:51:31 -0000
\r
26 From: David Bremner <david@tethera.net>
\r
27 To: notmuch@notmuchmail.org
\r
28 Subject: [Patch v6 5/7] CLI: add notmuch-config support for named queries
\r
29 Date: Wed, 25 May 2016 07:51:24 -0300
\r
30 Message-Id: <1464173486-23032-6-git-send-email-david@tethera.net>
\r
31 X-Mailer: git-send-email 2.8.1
\r
32 In-Reply-To: <1464173486-23032-1-git-send-email-david@tethera.net>
\r
33 References: <1464173486-23032-1-git-send-email-david@tethera.net>
\r
34 X-BeenThere: notmuch@notmuchmail.org
\r
35 X-Mailman-Version: 2.1.20
\r
37 List-Id: "Use and development of the notmuch mail system."
\r
38 <notmuch.notmuchmail.org>
\r
39 List-Unsubscribe: <https://notmuchmail.org/mailman/options/notmuch>,
\r
40 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
41 List-Archive: <http://notmuchmail.org/pipermail/notmuch/>
\r
42 List-Post: <mailto:notmuch@notmuchmail.org>
\r
43 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
44 List-Subscribe: <https://notmuchmail.org/mailman/listinfo/notmuch>,
\r
45 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
46 X-List-Received-Date: Wed, 25 May 2016 10:51:46 -0000
\r
48 Most of the infrastructure here is general, only the validation/dispatch
\r
49 is hardcoded to a particular prefix.
\r
51 A notable change in behaviour is that notmuch-config now opens the
\r
52 database e.g. on every call to list, which fails with an error message
\r
53 if the database doesn't exit yet.
\r
55 doc/man1/notmuch-config.rst | 6 ++++
\r
56 notmuch-config.c | 88 ++++++++++++++++++++++++++++++++++++++++++++-
\r
57 test/Makefile.local | 2 +-
\r
58 test/T030-config.sh | 12 ++++---
\r
59 test/T600-named-queries.sh | 53 +++++++++++++++++++++++++++
\r
60 test/test-lib.sh | 5 +++
\r
61 6 files changed, 159 insertions(+), 7 deletions(-)
\r
62 create mode 100755 test/T600-named-queries.sh
\r
64 diff --git a/doc/man1/notmuch-config.rst b/doc/man1/notmuch-config.rst
\r
65 index 26a8eb1..5a517eb 100644
\r
66 --- a/doc/man1/notmuch-config.rst
\r
67 +++ b/doc/man1/notmuch-config.rst
\r
68 @@ -138,6 +138,12 @@ The available configuration items are described below.
\r
69 "compact" (see **notmuch-compact(1)**)
\r
70 and "field_processor" (see **notmuch-search-terms(7)**).
\r
74 + Expansion for named query called <name>. See
\r
75 + **notmuch-search-terms(7)** for more information about named
\r
81 diff --git a/notmuch-config.c b/notmuch-config.c
\r
82 index 01bb185..c618f2c 100644
\r
83 --- a/notmuch-config.c
\r
84 +++ b/notmuch-config.c
\r
85 @@ -751,6 +751,28 @@ _item_split (char *item, char **group, char **key)
\r
88 #define BUILT_WITH_PREFIX "built_with."
\r
89 +#define QUERY_PREFIX "query."
\r
92 +_print_db_config(notmuch_config_t *config, const char *name)
\r
94 + notmuch_database_t *notmuch;
\r
97 + if (notmuch_database_open (notmuch_config_get_database_path (config),
\r
98 + NOTMUCH_DATABASE_MODE_READ_ONLY, ¬much))
\r
99 + return EXIT_FAILURE;
\r
101 + /* XXX Handle UUID mismatch? */
\r
103 + if (print_status_database ("notmuch config", notmuch,
\r
104 + notmuch_database_get_config (notmuch, name, &val)))
\r
105 + return EXIT_FAILURE;
\r
109 + return EXIT_SUCCESS;
\r
113 notmuch_config_command_get (notmuch_config_t *config, char *item)
\r
114 @@ -778,6 +800,8 @@ notmuch_config_command_get (notmuch_config_t *config, char *item)
\r
115 } else if (STRNCMP_LITERAL (item, BUILT_WITH_PREFIX) == 0) {
\r
117 notmuch_built_with (item + strlen (BUILT_WITH_PREFIX)) ? "true" : "false");
\r
118 + } else if (STRNCMP_LITERAL (item, QUERY_PREFIX) == 0) {
\r
119 + return _print_db_config (config, item);
\r
123 @@ -805,6 +829,39 @@ notmuch_config_command_get (notmuch_config_t *config, char *item)
\r
127 +_set_db_config(notmuch_config_t *config, const char *key, int argc, char **argv)
\r
129 + notmuch_database_t *notmuch;
\r
130 + const char *val = "";
\r
133 + /* XXX handle lists? */
\r
134 + fprintf (stderr, "notmuch config set: at most one value expected for %s\n", key);
\r
135 + return EXIT_FAILURE;
\r
142 + if (notmuch_database_open (notmuch_config_get_database_path (config),
\r
143 + NOTMUCH_DATABASE_MODE_READ_WRITE, ¬much))
\r
144 + return EXIT_FAILURE;
\r
146 + /* XXX Handle UUID mismatch? */
\r
148 + if (print_status_database ("notmuch config", notmuch,
\r
149 + notmuch_database_set_config (notmuch, key, val)))
\r
150 + return EXIT_FAILURE;
\r
152 + if (print_status_database ("notmuch config", notmuch,
\r
153 + notmuch_database_close (notmuch)))
\r
154 + return EXIT_FAILURE;
\r
156 + return EXIT_SUCCESS;
\r
160 notmuch_config_command_set (notmuch_config_t *config, char *item, int argc, char *argv[])
\r
163 @@ -814,6 +871,10 @@ notmuch_config_command_set (notmuch_config_t *config, char *item, int argc, char
\r
167 + if (STRNCMP_LITERAL (item, QUERY_PREFIX) == 0) {
\r
168 + return _set_db_config (config, item, argc, argv);
\r
171 if (_item_split (item, &group, &key))
\r
174 @@ -853,6 +914,31 @@ _notmuch_config_list_built_with ()
\r
178 +_list_db_config (notmuch_config_t *config)
\r
180 + notmuch_database_t *notmuch;
\r
181 + notmuch_config_list_t *list;
\r
183 + if (notmuch_database_open (notmuch_config_get_database_path (config),
\r
184 + NOTMUCH_DATABASE_MODE_READ_ONLY, ¬much))
\r
185 + return EXIT_FAILURE;
\r
187 + /* XXX Handle UUID mismatch? */
\r
190 + if (print_status_database ("notmuch config", notmuch,
\r
191 + notmuch_database_get_config_list (notmuch, "", &list)))
\r
192 + return EXIT_FAILURE;
\r
194 + for (; notmuch_config_list_valid (list); notmuch_config_list_move_to_next (list)) {
\r
195 + printf("%s=%s\n", notmuch_config_list_key (list), notmuch_config_list_value(list));
\r
197 + notmuch_config_list_destroy (list);
\r
199 + return EXIT_SUCCESS;
\r
203 notmuch_config_command_list (notmuch_config_t *config)
\r
206 @@ -888,7 +974,7 @@ notmuch_config_command_list (notmuch_config_t *config)
\r
207 g_strfreev (groups);
\r
209 _notmuch_config_list_built_with ();
\r
211 + return _list_db_config (config);
\r
215 diff --git a/test/Makefile.local b/test/Makefile.local
\r
216 index 022f2cf..91b3693 100644
\r
217 --- a/test/Makefile.local
\r
218 +++ b/test/Makefile.local
\r
219 @@ -19,7 +19,7 @@ $(dir)/hex-xcode: $(dir)/hex-xcode.o command-line-arguments.o util/libutil.a
\r
220 $(call quiet,CC) $^ -o $@ $(LDFLAGS) $(TALLOC_LDFLAGS)
\r
222 random_corpus_deps = $(dir)/random-corpus.o $(dir)/database-test.o \
\r
223 - notmuch-config.o command-line-arguments.o \
\r
224 + notmuch-config.o status.o command-line-arguments.o \
\r
225 lib/libnotmuch.a util/libutil.a \
\r
226 parse-time-string/libparse-time-string.a
\r
228 diff --git a/test/T030-config.sh b/test/T030-config.sh
\r
229 index 437269f..b8d5a86 100755
\r
230 --- a/test/T030-config.sh
\r
231 +++ b/test/T030-config.sh
\r
232 @@ -43,10 +43,10 @@ notmuch config set foo.nonexistent
\r
233 test_expect_equal "$(notmuch config get foo.nonexistent)" ""
\r
235 test_begin_subtest "List all items"
\r
236 -notmuch config set database.path "/canonical/path"
\r
237 -output=$(notmuch config list | notmuch_built_with_sanitize)
\r
238 -test_expect_equal "$output" "\
\r
239 -database.path=/canonical/path
\r
240 +notmuch config list 2>&1 | notmuch_config_sanitize > OUTPUT
\r
241 +cat <<EOF > EXPECTED
\r
242 +Error opening database at MAIL_DIR/.notmuch: No such file or directory
\r
243 +database.path=MAIL_DIR
\r
244 user.name=Notmuch Test Suite
\r
245 user.primary_email=test_suite@notmuchmail.org
\r
246 user.other_email=test_suite_other@notmuchmail.org;test_suite@otherdomain.org
\r
247 @@ -58,7 +58,9 @@ crypto.gpg_path=gpg
\r
248 foo.string=this is another string value
\r
249 foo.list=this;is another;list value;
\r
250 built_with.compact=something
\r
251 -built_with.field_processor=something"
\r
252 +built_with.field_processor=something
\r
254 +test_expect_equal_file EXPECTED OUTPUT
\r
256 test_begin_subtest "Top level --config=FILE option"
\r
257 cp "${NOTMUCH_CONFIG}" alt-config
\r
258 diff --git a/test/T600-named-queries.sh b/test/T600-named-queries.sh
\r
259 new file mode 100755
\r
260 index 0000000..0922620
\r
262 +++ b/test/T600-named-queries.sh
\r
264 +#!/usr/bin/env bash
\r
265 +test_description='named queries'
\r
266 +. ./test-lib.sh || exit 1
\r
268 +QUERYSTR="date:2009-11-18..2009-11-18 and tag:unread"
\r
270 +test_expect_code 1 "error adding named query before initializing DB" \
\r
271 + "notmuch config set query.test \"$QUERYSTR\""
\r
275 +test_expect_success "adding named query" \
\r
276 + "notmuch config set query.test \"$QUERYSTR\""
\r
278 +QUERYSTR2="query:test and subject:Maildir"
\r
279 +test_expect_success "adding nested named query" \
\r
280 + "notmuch config set query.test2 \"$QUERYSTR2\""
\r
282 +test_begin_subtest "retrieve named query"
\r
283 +output=$(notmuch config get query.test)
\r
284 +test_expect_equal "$QUERYSTR" "$output"
\r
286 +test_begin_subtest "List all queries"
\r
287 +notmuch config list | grep ^query | notmuch_config_sanitize > OUTPUT
\r
288 +cat <<EOF > EXPECTED
\r
289 +query.test=date:2009-11-18..2009-11-18 and tag:unread
\r
290 +query.test2=query:test and subject:Maildir
\r
292 +test_expect_equal_file EXPECTED OUTPUT
\r
294 +test_begin_subtest "dump named queries"
\r
295 +notmuch dump | grep '^#@' > OUTPUT
\r
296 +cat<<EOF > QUERIES.BEFORE
\r
297 +#@ query.test date%3a2009-11-18..2009-11-18%20and%20tag%3aunread
\r
298 +#@ query.test2 query%3atest%20and%20subject%3aMaildir
\r
300 +test_expect_equal_file QUERIES.BEFORE OUTPUT
\r
302 +test_begin_subtest "delete named queries"
\r
303 +notmuch dump > BEFORE
\r
304 +notmuch config set query.test
\r
305 +notmuch dump | grep '^#@' > OUTPUT
\r
306 +cat<<EOF > EXPECTED
\r
307 +#@ query.test2 query%3atest%20and%20subject%3aMaildir
\r
309 +test_expect_equal_file EXPECTED OUTPUT
\r
311 +test_begin_subtest "restore named queries"
\r
312 +notmuch restore < BEFORE
\r
313 +notmuch dump | grep '^#@' > OUTPUT
\r
314 +test_expect_equal_file QUERIES.BEFORE OUTPUT
\r
317 diff --git a/test/test-lib.sh b/test/test-lib.sh
\r
318 index e439862..201d0eb 100644
\r
319 --- a/test/test-lib.sh
\r
320 +++ b/test/test-lib.sh
\r
321 @@ -746,6 +746,11 @@ notmuch_built_with_sanitize ()
\r
322 sed 's/^built_with[.]\(.*\)=.*$/built_with.\1=something/'
\r
325 +notmuch_config_sanitize ()
\r
327 + notmuch_dir_sanitize | notmuch_built_with_sanitize
\r
330 # End of notmuch helper functions
\r
332 # Use test_set_prereq to tell that a particular prerequisite is available.
\r