1 Return-Path: <jani@nikula.org>
\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 olra.theworths.org (Postfix) with ESMTP id 6C41F429E25
\r
6 for <notmuch@notmuchmail.org>; Sun, 3 Mar 2013 13:55:37 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
8 X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References"
\r
12 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5
\r
13 tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled
\r
14 Received: from olra.theworths.org ([127.0.0.1])
\r
15 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
16 with ESMTP id E50fYIkb1IFp for <notmuch@notmuchmail.org>;
\r
17 Sun, 3 Mar 2013 13:55:34 -0800 (PST)
\r
18 Received: from mail-lb0-f179.google.com (mail-lb0-f179.google.com
\r
19 [209.85.217.179]) (using TLSv1 with cipher RC4-SHA (128/128 bits))
\r
20 (No client certificate requested)
\r
21 by olra.theworths.org (Postfix) with ESMTPS id 942C8431FAE
\r
22 for <notmuch@notmuchmail.org>; Sun, 3 Mar 2013 13:55:25 -0800 (PST)
\r
23 Received: by mail-lb0-f179.google.com with SMTP id j14so3506579lbo.10
\r
24 for <notmuch@notmuchmail.org>; Sun, 03 Mar 2013 13:55:24 -0800 (PST)
\r
25 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
\r
26 d=google.com; s=20120113;
\r
27 h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to
\r
28 :references:in-reply-to:references:x-gm-message-state;
\r
29 bh=6yGGNMOFH3Wsp9Py5WltSKwvD9/MYnI7KjrSJpNuoO8=;
\r
30 b=T4GrSps9+5jNwmTU5MC59TRKbrpH2HQk5R8Jicoy3/MFgTZqsesP/GT8VKJlhSVOIh
\r
31 8DaWgbxH/oPr5KJqMFkvERGXwgmh460JzLFdD8oRYWVJ6Xf4Ev7yVH8zC7U2HS3Uq7hR
\r
32 nvry3cXWKpEM7KoybtSaBxAdD0A6VxTv/jpaqPFFoXK/Lyt6WsOUX80dKc/q4ZcUosru
\r
33 3KUdTs36vl14Wk0poP/GmB2cYqiGQCrRfSUdD6MaGP5ZGQZ/7XtNYFmo0kUrttn3vflO
\r
34 bL9/KdDmd5TUs/LvFyNoZNsP2fv4+f72yJ09xGMV9KRQLWauyOrgdWPp+G+c2P15VLNx
\r
36 X-Received: by 10.112.23.136 with SMTP id m8mr3665256lbf.53.1362347724020;
\r
37 Sun, 03 Mar 2013 13:55:24 -0800 (PST)
\r
38 Received: from localhost (dsl-hkibrasgw4-50df51-27.dhcp.inet.fi.
\r
40 by mx.google.com with ESMTPS id ev7sm6608297lbb.15.2013.03.03.13.55.22
\r
41 (version=TLSv1.2 cipher=RC4-SHA bits=128/128);
\r
42 Sun, 03 Mar 2013 13:55:23 -0800 (PST)
\r
43 From: Jani Nikula <jani@nikula.org>
\r
44 To: notmuch@notmuchmail.org
\r
45 Subject: [PATCH v2 4/6] cli: config: make notmuch_config_open() "is new"
\r
46 parameter input only
\r
47 Date: Sun, 3 Mar 2013 23:55:08 +0200
\r
49 <5faebfc5d36d7e85a4dd1acbca0417d8a6a2602d.1362347362.git.jani@nikula.org>
\r
50 X-Mailer: git-send-email 1.7.10.4
\r
51 In-Reply-To: <cover.1362347362.git.jani@nikula.org>
\r
52 References: <cover.1362347362.git.jani@nikula.org>
\r
53 In-Reply-To: <cover.1362347362.git.jani@nikula.org>
\r
54 References: <cover.1362347362.git.jani@nikula.org>
\r
56 ALoCoQlar5YEbUpyT5C+8HigLFhRYDpD5/dponXclI3wg6H1pc09IP5yO4ATzXFtPmQfViXlnz22
\r
57 X-BeenThere: notmuch@notmuchmail.org
\r
58 X-Mailman-Version: 2.1.13
\r
60 List-Id: "Use and development of the notmuch mail system."
\r
61 <notmuch.notmuchmail.org>
\r
62 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
63 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
64 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
65 List-Post: <mailto:notmuch@notmuchmail.org>
\r
66 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
67 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
68 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
69 X-List-Received-Date: Sun, 03 Mar 2013 21:55:38 -0000
\r
71 We now have a notmuch_config_is_new() function to query whether a
\r
72 config was created or not. Change the notmuch_config_open() is_new
\r
73 parameter into boolean create_new to determine whether the function
\r
74 should create a new config if one doesn't exist. This reduces the
\r
75 complexity of the API.
\r
77 notmuch-client.h | 2 +-
\r
78 notmuch-config.c | 32 +++++++++++---------------------
\r
79 notmuch-count.c | 2 +-
\r
80 notmuch-dump.c | 2 +-
\r
81 notmuch-new.c | 2 +-
\r
82 notmuch-reply.c | 2 +-
\r
83 notmuch-restore.c | 2 +-
\r
84 notmuch-search.c | 2 +-
\r
85 notmuch-setup.c | 7 +++----
\r
86 notmuch-show.c | 2 +-
\r
87 notmuch-tag.c | 2 +-
\r
89 test/random-corpus.c | 2 +-
\r
90 13 files changed, 26 insertions(+), 38 deletions(-)
\r
92 diff --git a/notmuch-client.h b/notmuch-client.h
\r
93 index 07367e0..b3dcb21 100644
\r
94 --- a/notmuch-client.h
\r
95 +++ b/notmuch-client.h
\r
96 @@ -248,7 +248,7 @@ typedef struct _notmuch_config notmuch_config_t;
\r
98 notmuch_config_open (void *ctx,
\r
99 const char *filename,
\r
100 - notmuch_bool_t *is_new_ret);
\r
101 + notmuch_bool_t create_new);
\r
104 notmuch_config_close (notmuch_config_t *config);
\r
105 diff --git a/notmuch-config.c b/notmuch-config.c
\r
106 index e733e92..247fbe4 100644
\r
107 --- a/notmuch-config.c
\r
108 +++ b/notmuch-config.c
\r
109 @@ -233,10 +233,9 @@ get_username_from_passwd_file (void *ctx)
\r
111 notmuch_config_open (void *ctx,
\r
112 const char *filename,
\r
113 - notmuch_bool_t *is_new_ret)
\r
114 + notmuch_bool_t create_new)
\r
116 GError *error = NULL;
\r
119 char *notmuch_config_env = NULL;
\r
120 int file_had_database_group;
\r
121 @@ -245,9 +244,6 @@ notmuch_config_open (void *ctx,
\r
122 int file_had_maildir_group;
\r
123 int file_had_search_group;
\r
128 notmuch_config_t *config = talloc (ctx, notmuch_config_t);
\r
129 if (config == NULL) {
\r
130 fprintf (stderr, "Out of memory.\n");
\r
131 @@ -286,17 +282,16 @@ notmuch_config_open (void *ctx,
\r
132 G_KEY_FILE_KEEP_COMMENTS,
\r
135 - /* If the caller passed a non-NULL value for is_new_ret, then
\r
136 - * the caller is prepared for a default configuration file in
\r
137 - * the case of FILE NOT FOUND. Otherwise, any read failure is
\r
139 + /* If create_new is true, then the caller is prepared for a
\r
140 + * default configuration file in the case of FILE NOT
\r
141 + * FOUND. Otherwise, any read failure is an error.
\r
143 - if (is_new_ret &&
\r
144 + if (create_new &&
\r
145 error->domain == G_FILE_ERROR &&
\r
146 error->code == G_FILE_ERROR_NOENT)
\r
148 g_error_free (error);
\r
150 + config->is_new = TRUE;
\r
154 @@ -379,7 +374,7 @@ notmuch_config_open (void *ctx,
\r
157 if (notmuch_config_get_search_exclude_tags (config, &tmp) == NULL) {
\r
159 + if (config->is_new) {
\r
160 const char *tags[] = { "deleted", "spam" };
\r
161 notmuch_config_set_search_exclude_tags (config, tags, 2);
\r
163 @@ -399,7 +394,7 @@ notmuch_config_open (void *ctx,
\r
164 /* Whenever we know of configuration sections that don't appear in
\r
165 * the configuration file, we add some comments to help the user
\r
166 * understand what can be done. */
\r
168 + if (config->is_new)
\r
170 g_key_file_set_comment (config->key_file, NULL, NULL,
\r
171 toplevel_config_comment, NULL);
\r
172 @@ -434,11 +429,6 @@ notmuch_config_open (void *ctx,
\r
173 search_config_comment, NULL);
\r
177 - *is_new_ret = is_new;
\r
179 - config->is_new = is_new;
\r
184 @@ -719,7 +709,7 @@ notmuch_config_command_get (void *ctx, char *item)
\r
186 notmuch_config_t *config;
\r
188 - config = notmuch_config_open (ctx, NULL, NULL);
\r
189 + config = notmuch_config_open (ctx, NULL, FALSE);
\r
190 if (config == NULL)
\r
193 @@ -781,7 +771,7 @@ notmuch_config_command_set (void *ctx, char *item, int argc, char *argv[])
\r
194 if (_item_split (item, &group, &key))
\r
197 - config = notmuch_config_open (ctx, NULL, NULL);
\r
198 + config = notmuch_config_open (ctx, NULL, FALSE);
\r
199 if (config == NULL)
\r
202 @@ -818,7 +808,7 @@ notmuch_config_command_list (void *ctx)
\r
204 size_t g, groups_length;
\r
206 - config = notmuch_config_open (ctx, NULL, NULL);
\r
207 + config = notmuch_config_open (ctx, NULL, FALSE);
\r
208 if (config == NULL)
\r
211 diff --git a/notmuch-count.c b/notmuch-count.c
\r
212 index 2f98128..61722ed 100644
\r
213 --- a/notmuch-count.c
\r
214 +++ b/notmuch-count.c
\r
215 @@ -62,7 +62,7 @@ notmuch_count_command (void *ctx, int argc, char *argv[])
\r
219 - config = notmuch_config_open (ctx, NULL, NULL);
\r
220 + config = notmuch_config_open (ctx, NULL, FALSE);
\r
221 if (config == NULL)
\r
224 diff --git a/notmuch-dump.c b/notmuch-dump.c
\r
225 index a3244e0..845a67e 100644
\r
226 --- a/notmuch-dump.c
\r
227 +++ b/notmuch-dump.c
\r
228 @@ -34,7 +34,7 @@ notmuch_dump_command (unused (void *ctx), int argc, char *argv[])
\r
229 notmuch_tags_t *tags;
\r
230 const char *query_str = "";
\r
232 - config = notmuch_config_open (ctx, NULL, NULL);
\r
233 + config = notmuch_config_open (ctx, NULL, FALSE);
\r
234 if (config == NULL)
\r
237 diff --git a/notmuch-new.c b/notmuch-new.c
\r
238 index feb9c32..4915418 100644
\r
239 --- a/notmuch-new.c
\r
240 +++ b/notmuch-new.c
\r
241 @@ -875,7 +875,7 @@ notmuch_new_command (void *ctx, int argc, char *argv[])
\r
245 - config = notmuch_config_open (ctx, NULL, NULL);
\r
246 + config = notmuch_config_open (ctx, NULL, FALSE);
\r
247 if (config == NULL)
\r
250 diff --git a/notmuch-reply.c b/notmuch-reply.c
\r
251 index 22c58ff..9da42b9 100644
\r
252 --- a/notmuch-reply.c
\r
253 +++ b/notmuch-reply.c
\r
254 @@ -762,7 +762,7 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])
\r
256 notmuch_exit_if_unsupported_format ();
\r
258 - config = notmuch_config_open (ctx, NULL, NULL);
\r
259 + config = notmuch_config_open (ctx, NULL, FALSE);
\r
260 if (config == NULL)
\r
263 diff --git a/notmuch-restore.c b/notmuch-restore.c
\r
264 index cf26a42..dd2507f 100644
\r
265 --- a/notmuch-restore.c
\r
266 +++ b/notmuch-restore.c
\r
267 @@ -139,7 +139,7 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])
\r
269 int input_format = DUMP_FORMAT_AUTO;
\r
271 - config = notmuch_config_open (ctx, NULL, NULL);
\r
272 + config = notmuch_config_open (ctx, NULL, FALSE);
\r
273 if (config == NULL)
\r
276 diff --git a/notmuch-search.c b/notmuch-search.c
\r
277 index 0b0a879..fac6663 100644
\r
278 --- a/notmuch-search.c
\r
279 +++ b/notmuch-search.c
\r
280 @@ -371,7 +371,7 @@ notmuch_search_command (void *ctx, int argc, char *argv[])
\r
282 notmuch_exit_if_unsupported_format ();
\r
284 - config = notmuch_config_open (ctx, NULL, NULL);
\r
285 + config = notmuch_config_open (ctx, NULL, FALSE);
\r
286 if (config == NULL)
\r
289 diff --git a/notmuch-setup.c b/notmuch-setup.c
\r
290 index 94d0aa7..72d862a 100644
\r
291 --- a/notmuch-setup.c
\r
292 +++ b/notmuch-setup.c
\r
293 @@ -130,7 +130,6 @@ notmuch_setup_command (unused (void *ctx),
\r
294 size_t old_other_emails_len;
\r
295 GPtrArray *other_emails;
\r
298 const char **new_tags;
\r
299 size_t new_tags_len;
\r
300 const char **search_exclude_tags;
\r
301 @@ -147,9 +146,9 @@ notmuch_setup_command (unused (void *ctx),
\r
302 chomp_newline (response); \
\r
305 - config = notmuch_config_open (ctx, NULL, &is_new);
\r
306 + config = notmuch_config_open (ctx, NULL, TRUE);
\r
309 + if (notmuch_config_is_new (config))
\r
310 welcome_message_pre_setup ();
\r
312 prompt ("Your full name [%s]: ", notmuch_config_get_user_name (config));
\r
313 @@ -229,7 +228,7 @@ notmuch_setup_command (unused (void *ctx),
\r
316 if (! notmuch_config_save (config)) {
\r
318 + if (notmuch_config_is_new (config))
\r
319 welcome_message_post_setup ();
\r
322 diff --git a/notmuch-show.c b/notmuch-show.c
\r
323 index cbfc2d1..5ae5d7d 100644
\r
324 --- a/notmuch-show.c
\r
325 +++ b/notmuch-show.c
\r
326 @@ -1176,7 +1176,7 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))
\r
328 params.entire_thread = FALSE;
\r
330 - config = notmuch_config_open (ctx, NULL, NULL);
\r
331 + config = notmuch_config_open (ctx, NULL, FALSE);
\r
332 if (config == NULL)
\r
335 diff --git a/notmuch-tag.c b/notmuch-tag.c
\r
336 index d9daf8f..148e856 100644
\r
337 --- a/notmuch-tag.c
\r
338 +++ b/notmuch-tag.c
\r
339 @@ -236,7 +236,7 @@ notmuch_tag_command (void *ctx, int argc, char *argv[])
\r
343 - config = notmuch_config_open (ctx, NULL, NULL);
\r
344 + config = notmuch_config_open (ctx, NULL, FALSE);
\r
345 if (config == NULL)
\r
348 diff --git a/notmuch.c b/notmuch.c
\r
349 index ec2f20f..e434d03 100644
\r
352 @@ -202,16 +202,15 @@ static int
\r
353 notmuch_command (void *ctx, unused(int argc), unused(char *argv[]))
\r
355 notmuch_config_t *config;
\r
356 - notmuch_bool_t is_new;
\r
360 - config = notmuch_config_open (ctx, NULL, &is_new);
\r
361 + config = notmuch_config_open (ctx, NULL, TRUE);
\r
363 /* If the user has never configured notmuch, then run
\r
364 * notmuch_setup_command which will give a nice welcome message,
\r
365 * and interactively guide the user through the configuration. */
\r
367 + if (notmuch_config_is_new (config)) {
\r
368 notmuch_config_close (config);
\r
369 return notmuch_setup_command (ctx, 0, NULL);
\r
371 diff --git a/test/random-corpus.c b/test/random-corpus.c
\r
372 index 8b7748e..790193d 100644
\r
373 --- a/test/random-corpus.c
\r
374 +++ b/test/random-corpus.c
\r
375 @@ -160,7 +160,7 @@ main (int argc, char **argv)
\r
379 - config = notmuch_config_open (ctx, config_path, NULL);
\r
380 + config = notmuch_config_open (ctx, config_path, FALSE);
\r
381 if (config == NULL)
\r