aboutsummaryrefslogtreecommitdiffhomepage
path: root/notmuch-new.c
diff options
context:
space:
mode:
authorGravatar Jani Nikula <jani@nikula.org>2013-03-03 23:55:09 +0200
committerGravatar David Bremner <bremner@debian.org>2013-03-08 07:54:41 -0400
commit4ef2106792439f5ade157b3ba3b8f7fa86fcb3ed (patch)
tree892c4e1a8826b324eea1492d19b156b46ae95a06 /notmuch-new.c
parente76f6517de020783d828be59f461f1d4f465c4b4 (diff)
cli: move config open/close to main() from subcommands
This allows specifying config file as a top level argument to notmuch, and generally makes it possible to override config file options in main(), without having to touch the subcommands. If the config file does not exist, one will be created for the notmuch main command and setup and help subcommands. Help is special in this regard; the config is created just to avoid errors about missing config, but it will not be saved. This also makes notmuch config the talloc context for subcommands.
Diffstat (limited to 'notmuch-new.c')
-rw-r--r--notmuch-new.c17
1 files changed, 6 insertions, 11 deletions
diff --git a/notmuch-new.c b/notmuch-new.c
index 49154180..faa33f1f 100644
--- a/notmuch-new.c
+++ b/notmuch-new.c
@@ -840,9 +840,8 @@ _remove_directory (void *ctx,
}
int
-notmuch_new_command (void *ctx, int argc, char *argv[])
+notmuch_new_command (notmuch_config_t *config, int argc, char *argv[])
{
- notmuch_config_t *config;
notmuch_database_t *notmuch;
add_files_state_t add_files_state;
double elapsed;
@@ -875,10 +874,6 @@ notmuch_new_command (void *ctx, int argc, char *argv[])
return 1;
}
- config = notmuch_config_open (ctx, NULL, FALSE);
- if (config == NULL)
- return 1;
-
add_files_state.new_tags = notmuch_config_get_new_tags (config, &add_files_state.new_tags_length);
add_files_state.new_ignore = notmuch_config_get_new_ignore (config, &add_files_state.new_ignore_length);
add_files_state.synchronize_flags = notmuch_config_get_maildir_synchronize_flags (config);
@@ -890,7 +885,7 @@ notmuch_new_command (void *ctx, int argc, char *argv[])
return ret;
}
- dot_notmuch_path = talloc_asprintf (ctx, "%s/%s", db_path, ".notmuch");
+ dot_notmuch_path = talloc_asprintf (config, "%s/%s", db_path, ".notmuch");
if (stat (dot_notmuch_path, &st)) {
int count;
@@ -941,9 +936,9 @@ notmuch_new_command (void *ctx, int argc, char *argv[])
add_files_state.removed_messages = add_files_state.renamed_messages = 0;
gettimeofday (&add_files_state.tv_start, NULL);
- add_files_state.removed_files = _filename_list_create (ctx);
- add_files_state.removed_directories = _filename_list_create (ctx);
- add_files_state.directory_mtimes = _filename_list_create (ctx);
+ add_files_state.removed_files = _filename_list_create (config);
+ add_files_state.removed_directories = _filename_list_create (config);
+ add_files_state.directory_mtimes = _filename_list_create (config);
if (! debugger_is_active () && add_files_state.output_is_a_tty
&& ! add_files_state.verbose) {
@@ -970,7 +965,7 @@ notmuch_new_command (void *ctx, int argc, char *argv[])
gettimeofday (&tv_start, NULL);
for (f = add_files_state.removed_directories->head, i = 0; f && !interrupted; f = f->next, i++) {
- ret = _remove_directory (ctx, notmuch, f->filename, &add_files_state);
+ ret = _remove_directory (config, notmuch, f->filename, &add_files_state);
if (ret)
goto DONE;
if (do_print_progress) {