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 CF703431FBD
\r
6 for <notmuch@notmuchmail.org>; Tue, 29 Jan 2013 13:47:10 -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 kV5TRnHCUHEK for <notmuch@notmuchmail.org>;
\r
17 Tue, 29 Jan 2013 13:47:07 -0800 (PST)
\r
18 Received: from mail-lb0-f176.google.com (mail-lb0-f176.google.com
\r
19 [209.85.217.176]) (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 380AF431FC7
\r
22 for <notmuch@notmuchmail.org>; Tue, 29 Jan 2013 13:46:59 -0800 (PST)
\r
23 Received: by mail-lb0-f176.google.com with SMTP id s4so1340488lbc.35
\r
24 for <notmuch@notmuchmail.org>; Tue, 29 Jan 2013 13:46:57 -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:subject:date:message-id:x-mailer:in-reply-to
\r
28 :references:in-reply-to:references:x-gm-message-state;
\r
29 bh=4t2uEylr2N5obOfCLkTkGVzs1Ec2uAUIcZvFbmFI3dE=;
\r
30 b=JbUXHFpBT+O/rDowxgsmN0sC+BQTxSPVd/1U23L3sWs7FU01J/X8AquL0Vb1gnHmNz
\r
31 s/+Duoyupwnz9VXPdOf7BucMbWck21ed3d9gtO+ryeA9OLYh65siUm/88St2rLv6Dlg5
\r
32 c8mdhaLUW/Uv5mv9jnFQNxANh5JTtpOX6G+CvydOt55srfCxtDzFv4XL4Ra2hMANoqnu
\r
33 k6uMvXuwdUzR57wIzIk7nrIUER7wNDIK0sp5QWil1/Oh9KUinFqusbv/mKXlmkbLmtwg
\r
34 IpUgclfYjqx0xbWa8UFiJoz5v3NJZ/II5WJqQofIC39Phgs2GIsyhnzYwLk94XmxGJZV
\r
36 X-Received: by 10.112.40.228 with SMTP id a4mr1071015lbl.26.1359496017633;
\r
37 Tue, 29 Jan 2013 13:46:57 -0800 (PST)
\r
38 Received: from localhost (dsl-hkibrasgw4-50df51-27.dhcp.inet.fi.
\r
40 by mx.google.com with ESMTPS id ew10sm5593460lbb.10.2013.01.29.13.46.55
\r
41 (version=TLSv1.2 cipher=RC4-SHA bits=128/128);
\r
42 Tue, 29 Jan 2013 13:46:56 -0800 (PST)
\r
43 From: Jani Nikula <jani@nikula.org>
\r
44 To: notmuch@notmuchmail.org
\r
45 Subject: [PATCH 5/6] cli: move config open/close to main() from subcommands
\r
46 Date: Tue, 29 Jan 2013 23:46:23 +0200
\r
48 <b6b3571c9bb31621d17d61a9bf7a2401577fb213.1359495450.git.jani@nikula.org>
\r
49 X-Mailer: git-send-email 1.7.10.4
\r
50 In-Reply-To: <cover.1359495450.git.jani@nikula.org>
\r
51 References: <cover.1359495450.git.jani@nikula.org>
\r
52 In-Reply-To: <cover.1359495450.git.jani@nikula.org>
\r
53 References: <cover.1359495450.git.jani@nikula.org>
\r
55 ALoCoQlLVB+b+0L+3JL7lZ7hS8N6abYoVFZth5Zq7LX0apkxW2HFFrnhSuDuTzuRUUU6pyo1torh
\r
56 X-BeenThere: notmuch@notmuchmail.org
\r
57 X-Mailman-Version: 2.1.13
\r
59 List-Id: "Use and development of the notmuch mail system."
\r
60 <notmuch.notmuchmail.org>
\r
61 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
62 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
63 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
64 List-Post: <mailto:notmuch@notmuchmail.org>
\r
65 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
66 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
67 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
68 X-List-Received-Date: Tue, 29 Jan 2013 21:47:11 -0000
\r
70 This allows specifying config file as a top level argument to notmuch,
\r
71 and generally makes it possible to override config file options in
\r
72 main(), without having to touch the subcommands.
\r
74 This also makes notmuch config the talloc context for subcommands.
\r
76 notmuch-client.h | 30 +++++++++++---------------
\r
77 notmuch-config.c | 40 +++++++----------------------------
\r
78 notmuch-count.c | 11 +++-------
\r
79 notmuch-dump.c | 7 +-----
\r
80 notmuch-new.c | 17 ++++++---------
\r
81 notmuch-reply.c | 15 +++++--------
\r
82 notmuch-restore.c | 11 +++-------
\r
83 notmuch-search.c | 15 +++++--------
\r
84 notmuch-setup.c | 17 ++++++---------
\r
85 notmuch-show.c | 15 +++++--------
\r
86 notmuch-tag.c | 15 +++++--------
\r
87 notmuch.c | 61 +++++++++++++++++++++++++++--------------------------
\r
88 12 files changed, 91 insertions(+), 163 deletions(-)
\r
90 diff --git a/notmuch-client.h b/notmuch-client.h
\r
91 index b3dcb21..45749a6 100644
\r
92 --- a/notmuch-client.h
\r
93 +++ b/notmuch-client.h
\r
94 @@ -150,6 +150,8 @@ chomp_newline (char *str)
\r
96 extern int notmuch_format_version;
\r
98 +typedef struct _notmuch_config notmuch_config_t;
\r
100 /* Commands that support structured output should support the
\r
101 * following argument
\r
102 * { NOTMUCH_OPT_INT, ¬much_format_version, "format-version", 0, 0 }
\r
103 @@ -169,40 +171,34 @@ int
\r
104 notmuch_crypto_cleanup (notmuch_crypto_t *crypto);
\r
107 -notmuch_count_command (void *ctx, int argc, char *argv[]);
\r
110 -notmuch_dump_command (void *ctx, int argc, char *argv[]);
\r
111 +notmuch_count_command (notmuch_config_t *config, int argc, char *argv[]);
\r
114 -notmuch_new_command (void *ctx, int argc, char *argv[]);
\r
115 +notmuch_dump_command (notmuch_config_t *config, int argc, char *argv[]);
\r
118 -notmuch_reply_command (void *ctx, int argc, char *argv[]);
\r
119 +notmuch_new_command (notmuch_config_t *config, int argc, char *argv[]);
\r
122 -notmuch_restore_command (void *ctx, int argc, char *argv[]);
\r
123 +notmuch_reply_command (notmuch_config_t *config, int argc, char *argv[]);
\r
126 -notmuch_search_command (void *ctx, int argc, char *argv[]);
\r
127 +notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[]);
\r
130 -notmuch_setup_command (void *ctx, int argc, char *argv[]);
\r
131 +notmuch_search_command (notmuch_config_t *config, int argc, char *argv[]);
\r
134 -notmuch_show_command (void *ctx, int argc, char *argv[]);
\r
135 +notmuch_setup_command (notmuch_config_t *config, int argc, char *argv[]);
\r
138 -notmuch_tag_command (void *ctx, int argc, char *argv[]);
\r
139 +notmuch_show_command (notmuch_config_t *config, int argc, char *argv[]);
\r
142 -notmuch_search_tags_command (void *ctx, int argc, char *argv[]);
\r
143 +notmuch_tag_command (notmuch_config_t *config, int argc, char *argv[]);
\r
146 -notmuch_cat_command (void *ctx, int argc, char *argv[]);
\r
149 -notmuch_config_command (void *ctx, int argc, char *argv[]);
\r
150 +notmuch_config_command (notmuch_config_t *config, int argc, char *argv[]);
\r
153 notmuch_time_relative_date (const void *ctx, time_t then);
\r
154 @@ -243,8 +239,6 @@ json_quote_str (const void *ctx, const char *str);
\r
156 /* notmuch-config.c */
\r
158 -typedef struct _notmuch_config notmuch_config_t;
\r
161 notmuch_config_open (void *ctx,
\r
162 const char *filename,
\r
163 diff --git a/notmuch-config.c b/notmuch-config.c
\r
164 index 247fbe4..48312e3 100644
\r
165 --- a/notmuch-config.c
\r
166 +++ b/notmuch-config.c
\r
167 @@ -705,14 +705,8 @@ _item_split (char *item, char **group, char **key)
\r
171 -notmuch_config_command_get (void *ctx, char *item)
\r
172 +notmuch_config_command_get (notmuch_config_t *config, char *item)
\r
174 - notmuch_config_t *config;
\r
176 - config = notmuch_config_open (ctx, NULL, FALSE);
\r
177 - if (config == NULL)
\r
180 if (strcmp(item, "database.path") == 0) {
\r
181 printf ("%s\n", notmuch_config_get_database_path (config));
\r
182 } else if (strcmp(item, "user.name") == 0) {
\r
183 @@ -756,25 +750,17 @@ notmuch_config_command_get (void *ctx, char *item)
\r
184 g_strfreev (value);
\r
187 - notmuch_config_close (config);
\r
193 -notmuch_config_command_set (void *ctx, char *item, int argc, char *argv[])
\r
194 +notmuch_config_command_set (notmuch_config_t *config, char *item, int argc, char *argv[])
\r
196 - notmuch_config_t *config;
\r
200 if (_item_split (item, &group, &key))
\r
203 - config = notmuch_config_open (ctx, NULL, FALSE);
\r
204 - if (config == NULL)
\r
207 /* With only the name of an item, we clear it from the
\r
208 * configuration file.
\r
210 @@ -795,23 +781,15 @@ notmuch_config_command_set (void *ctx, char *item, int argc, char *argv[])
\r
214 - ret = notmuch_config_save (config);
\r
215 - notmuch_config_close (config);
\r
218 + return notmuch_config_save (config);
\r
222 -notmuch_config_command_list (void *ctx)
\r
223 +notmuch_config_command_list (notmuch_config_t *config)
\r
225 - notmuch_config_t *config;
\r
227 size_t g, groups_length;
\r
229 - config = notmuch_config_open (ctx, NULL, FALSE);
\r
230 - if (config == NULL)
\r
233 groups = g_key_file_get_groups (config->key_file, &groups_length);
\r
234 if (groups == NULL)
\r
236 @@ -841,13 +819,11 @@ notmuch_config_command_list (void *ctx)
\r
238 g_strfreev (groups);
\r
240 - notmuch_config_close (config);
\r
246 -notmuch_config_command (void *ctx, int argc, char *argv[])
\r
247 +notmuch_config_command (notmuch_config_t *config, int argc, char *argv[])
\r
249 argc--; argv++; /* skip subcommand argument */
\r
251 @@ -862,16 +838,16 @@ notmuch_config_command (void *ctx, int argc, char *argv[])
\r
252 "one argument.\n");
\r
255 - return notmuch_config_command_get (ctx, argv[1]);
\r
256 + return notmuch_config_command_get (config, argv[1]);
\r
257 } else if (strcmp (argv[0], "set") == 0) {
\r
259 fprintf (stderr, "Error: notmuch config set requires at least "
\r
260 "one argument.\n");
\r
263 - return notmuch_config_command_set (ctx, argv[1], argc - 2, argv + 2);
\r
264 + return notmuch_config_command_set (config, argv[1], argc - 2, argv + 2);
\r
265 } else if (strcmp (argv[0], "list") == 0) {
\r
266 - return notmuch_config_command_list (ctx);
\r
267 + return notmuch_config_command_list (config);
\r
270 fprintf (stderr, "Unrecognized argument for notmuch config: %s\n",
\r
271 diff --git a/notmuch-count.c b/notmuch-count.c
\r
272 index 61722ed..390794f 100644
\r
273 --- a/notmuch-count.c
\r
274 +++ b/notmuch-count.c
\r
275 @@ -33,9 +33,8 @@ enum {
\r
279 -notmuch_count_command (void *ctx, int argc, char *argv[])
\r
280 +notmuch_count_command (notmuch_config_t *config, int argc, char *argv[])
\r
282 - notmuch_config_t *config;
\r
283 notmuch_database_t *notmuch;
\r
284 notmuch_query_t *query;
\r
286 @@ -62,22 +61,18 @@ notmuch_count_command (void *ctx, int argc, char *argv[])
\r
290 - config = notmuch_config_open (ctx, NULL, FALSE);
\r
291 - if (config == NULL)
\r
294 if (notmuch_database_open (notmuch_config_get_database_path (config),
\r
295 NOTMUCH_DATABASE_MODE_READ_ONLY, ¬much))
\r
298 - query_str = query_string_from_args (ctx, argc-opt_index, argv+opt_index);
\r
299 + query_str = query_string_from_args (config, argc-opt_index, argv+opt_index);
\r
300 if (query_str == NULL) {
\r
301 fprintf (stderr, "Out of memory.\n");
\r
305 if (*query_str == '\0') {
\r
306 - query_str = talloc_strdup (ctx, "");
\r
307 + query_str = talloc_strdup (config, "");
\r
310 query = notmuch_query_create (notmuch, query_str);
\r
311 diff --git a/notmuch-dump.c b/notmuch-dump.c
\r
312 index 845a67e..2024e30 100644
\r
313 --- a/notmuch-dump.c
\r
314 +++ b/notmuch-dump.c
\r
316 #include "string-util.h"
\r
319 -notmuch_dump_command (unused (void *ctx), int argc, char *argv[])
\r
320 +notmuch_dump_command (notmuch_config_t *config, int argc, char *argv[])
\r
322 - notmuch_config_t *config;
\r
323 notmuch_database_t *notmuch;
\r
324 notmuch_query_t *query;
\r
325 FILE *output = stdout;
\r
326 @@ -34,10 +33,6 @@ notmuch_dump_command (unused (void *ctx), int argc, char *argv[])
\r
327 notmuch_tags_t *tags;
\r
328 const char *query_str = "";
\r
330 - config = notmuch_config_open (ctx, NULL, FALSE);
\r
331 - if (config == NULL)
\r
334 if (notmuch_database_open (notmuch_config_get_database_path (config),
\r
335 NOTMUCH_DATABASE_MODE_READ_ONLY, ¬much))
\r
337 diff --git a/notmuch-new.c b/notmuch-new.c
\r
338 index 4915418..faa33f1 100644
\r
339 --- a/notmuch-new.c
\r
340 +++ b/notmuch-new.c
\r
341 @@ -840,9 +840,8 @@ _remove_directory (void *ctx,
\r
345 -notmuch_new_command (void *ctx, int argc, char *argv[])
\r
346 +notmuch_new_command (notmuch_config_t *config, int argc, char *argv[])
\r
348 - notmuch_config_t *config;
\r
349 notmuch_database_t *notmuch;
\r
350 add_files_state_t add_files_state;
\r
352 @@ -875,10 +874,6 @@ notmuch_new_command (void *ctx, int argc, char *argv[])
\r
356 - config = notmuch_config_open (ctx, NULL, FALSE);
\r
357 - if (config == NULL)
\r
360 add_files_state.new_tags = notmuch_config_get_new_tags (config, &add_files_state.new_tags_length);
\r
361 add_files_state.new_ignore = notmuch_config_get_new_ignore (config, &add_files_state.new_ignore_length);
\r
362 add_files_state.synchronize_flags = notmuch_config_get_maildir_synchronize_flags (config);
\r
363 @@ -890,7 +885,7 @@ notmuch_new_command (void *ctx, int argc, char *argv[])
\r
367 - dot_notmuch_path = talloc_asprintf (ctx, "%s/%s", db_path, ".notmuch");
\r
368 + dot_notmuch_path = talloc_asprintf (config, "%s/%s", db_path, ".notmuch");
\r
370 if (stat (dot_notmuch_path, &st)) {
\r
372 @@ -941,9 +936,9 @@ notmuch_new_command (void *ctx, int argc, char *argv[])
\r
373 add_files_state.removed_messages = add_files_state.renamed_messages = 0;
\r
374 gettimeofday (&add_files_state.tv_start, NULL);
\r
376 - add_files_state.removed_files = _filename_list_create (ctx);
\r
377 - add_files_state.removed_directories = _filename_list_create (ctx);
\r
378 - add_files_state.directory_mtimes = _filename_list_create (ctx);
\r
379 + add_files_state.removed_files = _filename_list_create (config);
\r
380 + add_files_state.removed_directories = _filename_list_create (config);
\r
381 + add_files_state.directory_mtimes = _filename_list_create (config);
\r
383 if (! debugger_is_active () && add_files_state.output_is_a_tty
\r
384 && ! add_files_state.verbose) {
\r
385 @@ -970,7 +965,7 @@ notmuch_new_command (void *ctx, int argc, char *argv[])
\r
387 gettimeofday (&tv_start, NULL);
\r
388 for (f = add_files_state.removed_directories->head, i = 0; f && !interrupted; f = f->next, i++) {
\r
389 - ret = _remove_directory (ctx, notmuch, f->filename, &add_files_state);
\r
390 + ret = _remove_directory (config, notmuch, f->filename, &add_files_state);
\r
393 if (do_print_progress) {
\r
394 diff --git a/notmuch-reply.c b/notmuch-reply.c
\r
395 index 9da42b9..e151f78 100644
\r
396 --- a/notmuch-reply.c
\r
397 +++ b/notmuch-reply.c
\r
398 @@ -702,9 +702,8 @@ enum {
\r
402 -notmuch_reply_command (void *ctx, int argc, char *argv[])
\r
403 +notmuch_reply_command (notmuch_config_t *config, int argc, char *argv[])
\r
405 - notmuch_config_t *config;
\r
406 notmuch_database_t *notmuch;
\r
407 notmuch_query_t *query;
\r
408 char *query_string;
\r
409 @@ -752,21 +751,17 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])
\r
410 reply_format_func = notmuch_reply_format_headers_only;
\r
411 } else if (format == FORMAT_JSON) {
\r
412 reply_format_func = notmuch_reply_format_sprinter;
\r
413 - sp = sprinter_json_create (ctx, stdout);
\r
414 + sp = sprinter_json_create (config, stdout);
\r
415 } else if (format == FORMAT_SEXP) {
\r
416 reply_format_func = notmuch_reply_format_sprinter;
\r
417 - sp = sprinter_sexp_create (ctx, stdout);
\r
418 + sp = sprinter_sexp_create (config, stdout);
\r
420 reply_format_func = notmuch_reply_format_default;
\r
423 notmuch_exit_if_unsupported_format ();
\r
425 - config = notmuch_config_open (ctx, NULL, FALSE);
\r
426 - if (config == NULL)
\r
429 - query_string = query_string_from_args (ctx, argc-opt_index, argv+opt_index);
\r
430 + query_string = query_string_from_args (config, argc-opt_index, argv+opt_index);
\r
431 if (query_string == NULL) {
\r
432 fprintf (stderr, "Out of memory\n");
\r
434 @@ -787,7 +782,7 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])
\r
438 - if (reply_format_func (ctx, config, query, ¶ms, reply_all, sp) != 0)
\r
439 + if (reply_format_func (config, config, query, ¶ms, reply_all, sp) != 0)
\r
442 notmuch_crypto_cleanup (¶ms.crypto);
\r
443 diff --git a/notmuch-restore.c b/notmuch-restore.c
\r
444 index dd2507f..1419621 100644
\r
445 --- a/notmuch-restore.c
\r
446 +++ b/notmuch-restore.c
\r
447 @@ -120,9 +120,8 @@ parse_sup_line (void *ctx, char *line,
\r
451 -notmuch_restore_command (unused (void *ctx), int argc, char *argv[])
\r
452 +notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[])
\r
454 - notmuch_config_t *config;
\r
455 notmuch_database_t *notmuch;
\r
456 notmuch_bool_t accumulate = FALSE;
\r
457 tag_op_flag_t flags = 0;
\r
458 @@ -139,10 +138,6 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])
\r
460 int input_format = DUMP_FORMAT_AUTO;
\r
462 - config = notmuch_config_open (ctx, NULL, FALSE);
\r
463 - if (config == NULL)
\r
466 if (notmuch_database_open (notmuch_config_get_database_path (config),
\r
467 NOTMUCH_DATABASE_MODE_READ_WRITE, ¬much))
\r
469 @@ -187,7 +182,7 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])
\r
473 - tag_ops = tag_op_list_create (ctx);
\r
474 + tag_ops = tag_op_list_create (config);
\r
475 if (tag_ops == NULL) {
\r
476 fprintf (stderr, "Out of memory.\n");
\r
478 @@ -226,7 +221,7 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])
\r
479 if (line_ctx != NULL)
\r
480 talloc_free (line_ctx);
\r
482 - line_ctx = talloc_new (ctx);
\r
483 + line_ctx = talloc_new (config);
\r
484 if (input_format == DUMP_FORMAT_SUP) {
\r
485 ret = parse_sup_line (line_ctx, line, &query_string, tag_ops);
\r
487 diff --git a/notmuch-search.c b/notmuch-search.c
\r
488 index fac6663..e658639 100644
\r
489 --- a/notmuch-search.c
\r
490 +++ b/notmuch-search.c
\r
491 @@ -290,9 +290,8 @@ enum {
\r
495 -notmuch_search_command (void *ctx, int argc, char *argv[])
\r
496 +notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])
\r
498 - notmuch_config_t *config;
\r
499 notmuch_database_t *notmuch;
\r
500 notmuch_query_t *query;
\r
502 @@ -349,20 +348,20 @@ notmuch_search_command (void *ctx, int argc, char *argv[])
\r
504 switch (format_sel) {
\r
505 case NOTMUCH_FORMAT_TEXT:
\r
506 - format = sprinter_text_create (ctx, stdout);
\r
507 + format = sprinter_text_create (config, stdout);
\r
509 case NOTMUCH_FORMAT_TEXT0:
\r
510 if (output == OUTPUT_SUMMARY) {
\r
511 fprintf (stderr, "Error: --format=text0 is not compatible with --output=summary.\n");
\r
514 - format = sprinter_text0_create (ctx, stdout);
\r
515 + format = sprinter_text0_create (config, stdout);
\r
517 case NOTMUCH_FORMAT_JSON:
\r
518 - format = sprinter_json_create (ctx, stdout);
\r
519 + format = sprinter_json_create (config, stdout);
\r
521 case NOTMUCH_FORMAT_SEXP:
\r
522 - format = sprinter_sexp_create (ctx, stdout);
\r
523 + format = sprinter_sexp_create (config, stdout);
\r
526 /* this should never happen */
\r
527 @@ -371,10 +370,6 @@ notmuch_search_command (void *ctx, int argc, char *argv[])
\r
529 notmuch_exit_if_unsupported_format ();
\r
531 - config = notmuch_config_open (ctx, NULL, FALSE);
\r
532 - if (config == NULL)
\r
535 if (notmuch_database_open (notmuch_config_get_database_path (config),
\r
536 NOTMUCH_DATABASE_MODE_READ_ONLY, ¬much))
\r
538 diff --git a/notmuch-setup.c b/notmuch-setup.c
\r
539 index 72d862a..475248b 100644
\r
540 --- a/notmuch-setup.c
\r
541 +++ b/notmuch-setup.c
\r
542 @@ -120,12 +120,11 @@ parse_tag_list (void *ctx, char *response)
\r
546 -notmuch_setup_command (unused (void *ctx),
\r
547 +notmuch_setup_command (notmuch_config_t *config,
\r
548 unused (int argc), unused (char *argv[]))
\r
550 char *response = NULL;
\r
551 size_t response_size = 0;
\r
552 - notmuch_config_t *config;
\r
553 const char **old_other_emails;
\r
554 size_t old_other_emails_len;
\r
555 GPtrArray *other_emails;
\r
556 @@ -146,8 +145,6 @@ notmuch_setup_command (unused (void *ctx),
\r
557 chomp_newline (response); \
\r
560 - config = notmuch_config_open (ctx, NULL, TRUE);
\r
562 if (notmuch_config_is_new (config))
\r
563 welcome_message_pre_setup ();
\r
565 @@ -167,16 +164,16 @@ notmuch_setup_command (unused (void *ctx),
\r
566 for (i = 0; i < old_other_emails_len; i++) {
\r
567 prompt ("Additional email address [%s]: ", old_other_emails[i]);
\r
568 if (strlen (response))
\r
569 - g_ptr_array_add (other_emails, talloc_strdup (ctx, response));
\r
570 + g_ptr_array_add (other_emails, talloc_strdup (config, response));
\r
572 - g_ptr_array_add (other_emails, talloc_strdup (ctx,
\r
573 + g_ptr_array_add (other_emails, talloc_strdup (config,
\r
574 old_other_emails[i]));
\r
578 prompt ("Additional email address [Press 'Enter' if none]: ");
\r
579 if (strlen (response))
\r
580 - g_ptr_array_add (other_emails, talloc_strdup (ctx, response));
\r
581 + g_ptr_array_add (other_emails, talloc_strdup (config, response));
\r
582 } while (strlen (response));
\r
583 if (other_emails->len)
\r
584 notmuch_config_set_user_other_email (config,
\r
585 @@ -190,7 +187,7 @@ notmuch_setup_command (unused (void *ctx),
\r
586 if (strlen (response)) {
\r
587 const char *absolute_path;
\r
589 - absolute_path = make_path_absolute (ctx, response);
\r
590 + absolute_path = make_path_absolute (config, response);
\r
591 notmuch_config_set_database_path (config, absolute_path);
\r
594 @@ -201,7 +198,7 @@ notmuch_setup_command (unused (void *ctx),
\r
597 if (strlen (response)) {
\r
598 - GPtrArray *tags = parse_tag_list (ctx, response);
\r
599 + GPtrArray *tags = parse_tag_list (config, response);
\r
601 notmuch_config_set_new_tags (config, (const char **) tags->pdata,
\r
603 @@ -217,7 +214,7 @@ notmuch_setup_command (unused (void *ctx),
\r
606 if (strlen (response)) {
\r
607 - GPtrArray *tags = parse_tag_list (ctx, response);
\r
608 + GPtrArray *tags = parse_tag_list (config, response);
\r
610 notmuch_config_set_search_exclude_tags (config,
\r
611 (const char **) tags->pdata,
\r
612 diff --git a/notmuch-show.c b/notmuch-show.c
\r
613 index 5ae5d7d..c2ec122 100644
\r
614 --- a/notmuch-show.c
\r
615 +++ b/notmuch-show.c
\r
616 @@ -1056,9 +1056,8 @@ enum {
\r
620 -notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))
\r
621 +notmuch_show_command (notmuch_config_t *config, int argc, char *argv[])
\r
623 - notmuch_config_t *config;
\r
624 notmuch_database_t *notmuch;
\r
625 notmuch_query_t *query;
\r
626 char *query_string;
\r
627 @@ -1176,11 +1175,7 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))
\r
629 params.entire_thread = FALSE;
\r
631 - config = notmuch_config_open (ctx, NULL, FALSE);
\r
632 - if (config == NULL)
\r
635 - query_string = query_string_from_args (ctx, argc-opt_index, argv+opt_index);
\r
636 + query_string = query_string_from_args (config, argc-opt_index, argv+opt_index);
\r
637 if (query_string == NULL) {
\r
638 fprintf (stderr, "Out of memory\n");
\r
640 @@ -1202,11 +1197,11 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))
\r
643 /* Create structure printer. */
\r
644 - sprinter = format->new_sprinter(ctx, stdout);
\r
645 + sprinter = format->new_sprinter(config, stdout);
\r
647 /* If a single message is requested we do not use search_excludes. */
\r
648 if (params.part >= 0)
\r
649 - ret = do_show_single (ctx, query, format, sprinter, ¶ms);
\r
650 + ret = do_show_single (config, query, format, sprinter, ¶ms);
\r
652 /* We always apply set the exclude flag. The
\r
653 * exclude=true|false option controls whether or not we return
\r
654 @@ -1225,7 +1220,7 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))
\r
655 params.omit_excluded = FALSE;
\r
658 - ret = do_show (ctx, query, format, sprinter, ¶ms);
\r
659 + ret = do_show (config, query, format, sprinter, ¶ms);
\r
662 notmuch_crypto_cleanup (¶ms.crypto);
\r
663 diff --git a/notmuch-tag.c b/notmuch-tag.c
\r
664 index 148e856..0e73197 100644
\r
665 --- a/notmuch-tag.c
\r
666 +++ b/notmuch-tag.c
\r
667 @@ -178,11 +178,10 @@ tag_file (void *ctx, notmuch_database_t *notmuch, tag_op_flag_t flags,
\r
671 -notmuch_tag_command (void *ctx, int argc, char *argv[])
\r
672 +notmuch_tag_command (notmuch_config_t *config, int argc, char *argv[])
\r
674 tag_op_list_t *tag_ops = NULL;
\r
675 char *query_string = NULL;
\r
676 - notmuch_config_t *config;
\r
677 notmuch_database_t *notmuch;
\r
678 struct sigaction action;
\r
679 tag_op_flag_t tag_flags = TAG_FLAG_NONE;
\r
680 @@ -225,21 +224,17 @@ notmuch_tag_command (void *ctx, int argc, char *argv[])
\r
684 - tag_ops = tag_op_list_create (ctx);
\r
685 + tag_ops = tag_op_list_create (config);
\r
686 if (tag_ops == NULL) {
\r
687 fprintf (stderr, "Out of memory.\n");
\r
691 - if (parse_tag_command_line (ctx, argc - opt_index, argv + opt_index,
\r
692 + if (parse_tag_command_line (config, argc - opt_index, argv + opt_index,
\r
693 &query_string, tag_ops))
\r
697 - config = notmuch_config_open (ctx, NULL, FALSE);
\r
698 - if (config == NULL)
\r
701 if (notmuch_database_open (notmuch_config_get_database_path (config),
\r
702 NOTMUCH_DATABASE_MODE_READ_WRITE, ¬much))
\r
704 @@ -248,9 +243,9 @@ notmuch_tag_command (void *ctx, int argc, char *argv[])
\r
705 tag_flags |= TAG_FLAG_MAILDIR_SYNC;
\r
708 - ret = tag_file (ctx, notmuch, tag_flags, input);
\r
709 + ret = tag_file (config, notmuch, tag_flags, input);
\r
711 - ret = tag_query (ctx, notmuch, query_string, tag_ops, tag_flags);
\r
712 + ret = tag_query (config, notmuch, query_string, tag_ops, tag_flags);
\r
714 notmuch_database_destroy (notmuch);
\r
716 diff --git a/notmuch.c b/notmuch.c
\r
717 index 67d5772..f4bfeaa 100644
\r
720 @@ -22,56 +22,57 @@
\r
722 #include "notmuch-client.h"
\r
724 -typedef int (*command_function_t) (void *ctx, int argc, char *argv[]);
\r
725 +typedef int (*command_function_t) (notmuch_config_t *config, int argc, char *argv[]);
\r
727 typedef struct command {
\r
729 command_function_t function;
\r
730 + notmuch_bool_t create_config;
\r
731 const char *arguments;
\r
732 const char *summary;
\r
736 -notmuch_help_command (void *ctx, int argc, char *argv[]);
\r
737 +notmuch_help_command (notmuch_config_t *config, int argc, char *argv[]);
\r
740 -notmuch_command (void *ctx, int argc, char *argv[]);
\r
741 +notmuch_command (notmuch_config_t *config, int argc, char *argv[]);
\r
743 static command_t commands[] = {
\r
744 - { NULL, notmuch_command,
\r
745 + { NULL, notmuch_command, TRUE,
\r
747 "Notmuch main command." },
\r
748 - { "setup", notmuch_setup_command,
\r
749 + { "setup", notmuch_setup_command, TRUE,
\r
751 "Interactively setup notmuch for first use." },
\r
752 - { "new", notmuch_new_command,
\r
753 + { "new", notmuch_new_command, FALSE,
\r
755 "Find and import new messages to the notmuch database." },
\r
756 - { "search", notmuch_search_command,
\r
757 + { "search", notmuch_search_command, FALSE,
\r
758 "[options...] <search-terms> [...]",
\r
759 "Search for messages matching the given search terms." },
\r
760 - { "show", notmuch_show_command,
\r
761 + { "show", notmuch_show_command, FALSE,
\r
762 "<search-terms> [...]",
\r
763 "Show all messages matching the search terms." },
\r
764 - { "count", notmuch_count_command,
\r
765 + { "count", notmuch_count_command, FALSE,
\r
766 "[options...] <search-terms> [...]",
\r
767 "Count messages matching the search terms." },
\r
768 - { "reply", notmuch_reply_command,
\r
769 + { "reply", notmuch_reply_command, FALSE,
\r
770 "[options...] <search-terms> [...]",
\r
771 "Construct a reply template for a set of messages." },
\r
772 - { "tag", notmuch_tag_command,
\r
773 + { "tag", notmuch_tag_command, FALSE,
\r
774 "+<tag>|-<tag> [...] [--] <search-terms> [...]" ,
\r
775 "Add/remove tags for all messages matching the search terms." },
\r
776 - { "dump", notmuch_dump_command,
\r
777 + { "dump", notmuch_dump_command, FALSE,
\r
778 "[<filename>] [--] [<search-terms>]",
\r
779 "Create a plain-text dump of the tags for each message." },
\r
780 - { "restore", notmuch_restore_command,
\r
781 + { "restore", notmuch_restore_command, FALSE,
\r
782 "[--accumulate] [<filename>]",
\r
783 "Restore the tags from the given dump file (see 'dump')." },
\r
784 - { "config", notmuch_config_command,
\r
785 + { "config", notmuch_config_command, FALSE,
\r
786 "[get|set] <section>.<item> [value ...]",
\r
787 "Get or set settings in the notmuch configuration file." },
\r
788 - { "help", notmuch_help_command,
\r
789 + { "help", notmuch_help_command, FALSE,
\r
791 "This message, or more detailed help for the named command." }
\r
793 @@ -155,7 +156,7 @@ exec_man (const char *page)
\r
797 -notmuch_help_command (void *ctx, int argc, char *argv[])
\r
798 +notmuch_help_command (notmuch_config_t *config, int argc, char *argv[])
\r
800 command_t *command;
\r
802 @@ -178,7 +179,7 @@ notmuch_help_command (void *ctx, int argc, char *argv[])
\r
804 command = find_command (argv[0]);
\r
806 - char *page = talloc_asprintf (ctx, "notmuch-%s", command->name);
\r
807 + char *page = talloc_asprintf (config, "notmuch-%s", command->name);
\r
811 @@ -199,28 +200,23 @@ notmuch_help_command (void *ctx, int argc, char *argv[])
\r
812 * to be more clever about this in the future.
\r
815 -notmuch_command (void *ctx, unused(int argc), unused(char *argv[]))
\r
816 +notmuch_command (notmuch_config_t *config,
\r
817 + unused(int argc), unused(char *argv[]))
\r
819 - notmuch_config_t *config;
\r
823 - config = notmuch_config_open (ctx, NULL, TRUE);
\r
825 /* If the user has never configured notmuch, then run
\r
826 * notmuch_setup_command which will give a nice welcome message,
\r
827 * and interactively guide the user through the configuration. */
\r
828 - if (notmuch_config_is_new (config)) {
\r
829 - notmuch_config_close (config);
\r
830 - return notmuch_setup_command (ctx, 0, NULL);
\r
832 + if (notmuch_config_is_new (config))
\r
833 + return notmuch_setup_command (config, 0, NULL);
\r
835 /* Notmuch is already configured, but is there a database? */
\r
836 - db_path = talloc_asprintf (ctx, "%s/%s",
\r
837 + db_path = talloc_asprintf (config, "%s/%s",
\r
838 notmuch_config_get_database_path (config),
\r
840 if (stat (db_path, &st)) {
\r
841 - notmuch_config_close (config);
\r
842 if (errno != ENOENT) {
\r
843 fprintf (stderr, "Error looking for notmuch database at %s: %s\n",
\r
844 db_path, strerror (errno));
\r
845 @@ -252,8 +248,6 @@ notmuch_command (void *ctx, unused(int argc), unused(char *argv[]))
\r
846 notmuch_config_get_user_name (config),
\r
847 notmuch_config_get_user_primary_email (config));
\r
849 - notmuch_config_close (config);
\r
854 @@ -264,6 +258,7 @@ main (int argc, char *argv[])
\r
855 char *talloc_report;
\r
856 const char *command_name = NULL;
\r
857 command_t *command;
\r
858 + notmuch_config_t *config;
\r
859 notmuch_bool_t print_help=FALSE, print_version=FALSE;
\r
862 @@ -308,7 +303,13 @@ main (int argc, char *argv[])
\r
866 - ret = (command->function)(local, argc - opt_index, argv + opt_index);
\r
867 + config = notmuch_config_open (local, NULL, command->create_config);
\r
871 + ret = (command->function)(config, argc - opt_index, argv + opt_index);
\r
873 + notmuch_config_close (config);
\r
875 /* in the future support for this environment variable may
\r
876 * be supplemented or replaced by command line arguments
\r