database error
[notmuch-archives.git] / 1c / 6d08270dbbad42558611beca258d37493db4d3
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 39D626DE00CE\r
6  for <notmuch@notmuchmail.org>; Sun, 20 Mar 2016 09:53:33 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at cworth.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -0.029\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.029 tagged_above=-999 required=5\r
12  tests=[AWL=-0.018, SPF_PASS=-0.001, T_RP_MATCHES_RCVD=-0.01]\r
13  autolearn=disabled\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 JHmTq6sTHHp8 for <notmuch@notmuchmail.org>;\r
17  Sun, 20 Mar 2016 09:53:23 -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 942E36DE00D1\r
20  for <notmuch@notmuchmail.org>; Sun, 20 Mar 2016 09:53:23 -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 1ahgc0-0004IW-Ta; Sun, 20 Mar 2016 12:53:56 -0400\r
24 Received: (nullmailer pid 22041 invoked by uid 1000);\r
25  Sun, 20 Mar 2016 16:53:18 -0000\r
26 From: David Bremner <david@tethera.net>\r
27 To: David Bremner <david@tethera.net>, notmuch@notmuchmail.org\r
28 Subject: [PATCH] lib/cli: add library API / CLI for compile time options\r
29 Date: Sun, 20 Mar 2016 13:53:11 -0300\r
30 Message-Id: <1458492791-21991-1-git-send-email-david@tethera.net>\r
31 X-Mailer: git-send-email 2.7.0\r
32 In-Reply-To: <1458437904-17677-3-git-send-email-david@tethera.net>\r
33 References: <1458437904-17677-3-git-send-email-david@tethera.net>\r
34 MIME-Version: 1.0\r
35 Content-Type: text/plain; charset=UTF-8\r
36 Content-Transfer-Encoding: 8bit\r
37 X-BeenThere: notmuch@notmuchmail.org\r
38 X-Mailman-Version: 2.1.20\r
39 Precedence: list\r
40 List-Id: "Use and development of the notmuch mail system."\r
41  <notmuch.notmuchmail.org>\r
42 List-Unsubscribe: <https://notmuchmail.org/mailman/options/notmuch>,\r
43  <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
44 List-Archive: <http://notmuchmail.org/pipermail/notmuch/>\r
45 List-Post: <mailto:notmuch@notmuchmail.org>\r
46 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
47 List-Subscribe: <https://notmuchmail.org/mailman/listinfo/notmuch>,\r
48  <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
49 X-List-Received-Date: Sun, 20 Mar 2016 16:53:33 -0000\r
50 \r
51 This is intentionally low tech; if we have more than two options it may\r
52 make sense to build up what infrastructure is provided.\r
53 ---\r
54 \r
55 Here is attempt at answering some of the questions in\r
56 id:1458437904-17677-1-git-send-email-david@tethera.net\r
57 \r
58  lib/Makefile.local  |  1 +\r
59  lib/notmuch.h       | 10 ++++++++++\r
60  lib/options.c       | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++\r
61  notmuch-config.c    | 20 ++++++++++++++++++++\r
62  test/T030-config.sh |  6 ++++--\r
63  test/T040-setup.sh  |  6 ++++--\r
64  test/test-lib.sh    |  6 ++++++\r
65  7 files changed, 95 insertions(+), 4 deletions(-)\r
66  create mode 100644 lib/options.c\r
67 \r
68 diff --git a/lib/Makefile.local b/lib/Makefile.local\r
69 index 3a07090..4ad0158 100644\r
70 --- a/lib/Makefile.local\r
71 +++ b/lib/Makefile.local\r
72 @@ -39,6 +39,7 @@ libnotmuch_c_srcs =           \\r
73         $(dir)/message-file.c   \\r
74         $(dir)/messages.c       \\r
75         $(dir)/sha1.c           \\r
76 +       $(dir)/options.c        \\r
77         $(dir)/tags.c\r
78  \r
79  libnotmuch_cxx_srcs =          \\r
80 diff --git a/lib/notmuch.h b/lib/notmuch.h\r
81 index cb46fc0..b29dd5f 100644\r
82 --- a/lib/notmuch.h\r
83 +++ b/lib/notmuch.h\r
84 @@ -1838,6 +1838,16 @@ notmuch_filenames_move_to_next (notmuch_filenames_t *filenames);\r
85  void\r
86  notmuch_filenames_destroy (notmuch_filenames_t *filenames);\r
87  \r
88 +typedef enum {\r
89 +    NOTMUCH_OPTION_COMPACT = 1,\r
90 +    NOTMUCH_OPTION_FIELD_PROCESSOR = 2\r
91 +} notmuch_option_t;\r
92 +\r
93 +notmuch_bool_t\r
94 +notmuch_options_present (notmuch_option_t mask);\r
95 +\r
96 +notmuch_bool_t\r
97 +notmuch_options_get (const char *name);\r
98  /* @} */\r
99  \r
100  NOTMUCH_END_DECLS\r
101 diff --git a/lib/options.c b/lib/options.c\r
102 new file mode 100644\r
103 index 0000000..4e15d92\r
104 --- /dev/null\r
105 +++ b/lib/options.c\r
106 @@ -0,0 +1,50 @@\r
107 +/* notmuch - Not much of an email program, (just index and search)\r
108 + *\r
109 + * Copyright © 2016 David Bremner\r
110 + *\r
111 + * This program is free software: you can redistribute it and/or modify\r
112 + * it under the terms of the GNU General Public License as published by\r
113 + * the Free Software Foundation, either version 3 of the License, or\r
114 + * (at your option) any later version.\r
115 + *\r
116 + * This program is distributed in the hope that it will be useful,\r
117 + * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
118 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
119 + * GNU General Public License for more details.\r
120 + *\r
121 + * You should have received a copy of the GNU General Public License\r
122 + * along with this program.  If not, see http://www.gnu.org/licenses/ .\r
123 + *\r
124 + * Author: David Bremner <david@tethera.net>\r
125 + */\r
126 +\r
127 +#include "notmuch.h"\r
128 +#include "notmuch-private.h"\r
129 +\r
130 +notmuch_bool_t\r
131 +notmuch_options_present (notmuch_option_t mask)\r
132 +{\r
133 +    notmuch_option_t present = 0;\r
134 +\r
135 +#if HAVE_XAPIAN_COMPACT\r
136 +    present |= NOTMUCH_OPTION_COMPACT;\r
137 +#endif\r
138 +\r
139 +#if HAVE_XAPIAN_COMPACT\r
140 +    present |= NOTMUCH_OPTION_FIELD_PROCESSOR;\r
141 +#endif\r
142 +\r
143 +    return (mask & present) != 0;\r
144 +\r
145 +}\r
146 +\r
147 +notmuch_bool_t\r
148 +notmuch_options_get (const char *name) {\r
149 +    if (STRNCMP_LITERAL (name, "compact") == 0) {\r
150 +       return notmuch_options_present (NOTMUCH_OPTION_COMPACT);\r
151 +    } else if (STRNCMP_LITERAL (name, "field_processor") == 0) {\r
152 +       return notmuch_options_present (NOTMUCH_OPTION_FIELD_PROCESSOR);\r
153 +    } else {\r
154 +       return FALSE;\r
155 +    }\r
156 +}\r
157 diff --git a/notmuch-config.c b/notmuch-config.c\r
158 index d252bb2..cfc549d 100644\r
159 --- a/notmuch-config.c\r
160 +++ b/notmuch-config.c\r
161 @@ -750,6 +750,8 @@ _item_split (char *item, char **group, char **key)\r
162      return 0;\r
163  }\r
164  \r
165 +#define OPTION_PREFIX "options."\r
166 +\r
167  static int\r
168  notmuch_config_command_get (notmuch_config_t *config, char *item)\r
169  {\r
170 @@ -773,6 +775,9 @@ notmuch_config_command_get (notmuch_config_t *config, char *item)\r
171         tags = notmuch_config_get_new_tags (config, &length);\r
172         for (i = 0; i < length; i++)\r
173             printf ("%s\n", tags[i]);\r
174 +    } else if (STRNCMP_LITERAL (item, OPTION_PREFIX) == 0) {\r
175 +       printf ("%s\n",\r
176 +              notmuch_options_get (item + strlen (OPTION_PREFIX)) ? "true" : "false");\r
177      } else {\r
178         char **value;\r
179         size_t i, length;\r
180 @@ -804,6 +809,11 @@ notmuch_config_command_set (notmuch_config_t *config, char *item, int argc, char\r
181  {\r
182      char *group, *key;\r
183  \r
184 +    if (STRNCMP_LITERAL (item, OPTION_PREFIX) == 0) {\r
185 +       fprintf (stderr, "Error: read only option: %s\n", item);\r
186 +       return 1;\r
187 +    }\r
188 +\r
189      if (_item_split (item, &group, &key))\r
190         return 1;\r
191  \r
192 @@ -830,6 +840,15 @@ notmuch_config_command_set (notmuch_config_t *config, char *item, int argc, char\r
193      return notmuch_config_save (config);\r
194  }\r
195  \r
196 +static\r
197 +void\r
198 +_notmuch_config_list_options () {\r
199 +    printf("options.compact=%s\n",\r
200 +          notmuch_options_present(NOTMUCH_OPTION_COMPACT) ? "true" : "false");\r
201 +    printf("options.field_processor=%s\n",\r
202 +          notmuch_options_present(NOTMUCH_OPTION_FIELD_PROCESSOR) ? "true" : "false");\r
203 +}\r
204 +\r
205  static int\r
206  notmuch_config_command_list (notmuch_config_t *config)\r
207  {\r
208 @@ -865,6 +884,7 @@ notmuch_config_command_list (notmuch_config_t *config)\r
209  \r
210      g_strfreev (groups);\r
211  \r
212 +    _notmuch_config_list_options ();\r
213      return 0;\r
214  }\r
215  \r
216 diff --git a/test/T030-config.sh b/test/T030-config.sh\r
217 index f404908..c37ba21 100755\r
218 --- a/test/T030-config.sh\r
219 +++ b/test/T030-config.sh\r
220 @@ -44,7 +44,7 @@ test_expect_equal "$(notmuch config get foo.nonexistent)" ""\r
221  \r
222  test_begin_subtest "List all items"\r
223  notmuch config set database.path "/canonical/path"\r
224 -output=$(notmuch config list)\r
225 +output=$(notmuch config list | notmuch_options_sanitize)\r
226  test_expect_equal "$output" "\\r
227  database.path=/canonical/path\r
228  user.name=Notmuch Test Suite\r
229 @@ -56,7 +56,9 @@ search.exclude_tags=\r
230  maildir.synchronize_flags=true\r
231  crypto.gpg_path=gpg\r
232  foo.string=this is another string value\r
233 -foo.list=this;is another;list value;"\r
234 +foo.list=this;is another;list value;\r
235 +options.compact=something\r
236 +options.field_processor=something"\r
237  \r
238  test_begin_subtest "Top level --config=FILE option"\r
239  cp "${NOTMUCH_CONFIG}" alt-config\r
240 diff --git a/test/T040-setup.sh b/test/T040-setup.sh\r
241 index cf0c00b..5db03a6 100755\r
242 --- a/test/T040-setup.sh\r
243 +++ b/test/T040-setup.sh\r
244 @@ -19,7 +19,7 @@ another.suite@example.com\r
245  foo bar\r
246  baz\r
247  EOF\r
248 -output=$(notmuch --config=new-notmuch-config config list)\r
249 +output=$(notmuch --config=new-notmuch-config config list | notmuch_options_sanitize)\r
250  test_expect_equal "$output" "\\r
251  database.path=/path/to/maildir\r
252  user.name=Test Suite\r
253 @@ -29,6 +29,8 @@ new.tags=foo;bar;\r
254  new.ignore=\r
255  search.exclude_tags=baz;\r
256  maildir.synchronize_flags=true\r
257 -crypto.gpg_path=gpg"\r
258 +crypto.gpg_path=gpg\r
259 +options.compact=something\r
260 +options.field_processor=something"\r
261  \r
262  test_done\r
263 diff --git a/test/test-lib.sh b/test/test-lib.sh\r
264 index cc08a98..49e6f40 100644\r
265 --- a/test/test-lib.sh\r
266 +++ b/test/test-lib.sh\r
267 @@ -733,6 +733,12 @@ notmuch_uuid_sanitize ()\r
268  {\r
269      sed 's/[0-9a-f]\{8\}-[0-9a-f]\{4\}-[0-9a-f]\{4\}-[0-9a-f]\{4\}-[0-9a-f]\{12\}/UUID/g'\r
270  }\r
271 +\r
272 +notmuch_options_sanitize ()\r
273 +{\r
274 +    sed 's/^options[.]\(.*\)=.*$/options.\1=something/'\r
275 +}\r
276 +\r
277  # End of notmuch helper functions\r
278  \r
279  # Use test_set_prereq to tell that a particular prerequisite is available.\r
280 -- \r
281 2.7.0\r
282 \r