From 319efe21c9d2754c99951cecc71184faf7ca9054 Mon Sep 17 00:00:00 2001 From: David Bremner Date: Mon, 21 Dec 2020 08:55:14 -0400 Subject: [PATCH] CLI: add (unused) database argument to subcommands. This will allow transitioning individual subcommands to the new configuration framework. Eventually when they are all converted we can remove the notmuch_config_t * argument. For now, live with the parameter shadowing in some some subcommands; it will go away when they are converted. --- notmuch-client.h | 28 ++++++++++++++-------------- notmuch-compact.c | 2 +- notmuch-config.c | 2 +- notmuch-count.c | 2 +- notmuch-dump.c | 2 +- notmuch-insert.c | 2 +- notmuch-new.c | 2 +- notmuch-reindex.c | 2 +- notmuch-reply.c | 2 +- notmuch-restore.c | 2 +- notmuch-search.c | 4 ++-- notmuch-setup.c | 1 + notmuch-show.c | 2 +- notmuch-tag.c | 2 +- notmuch.c | 16 ++++++++++------ 15 files changed, 38 insertions(+), 33 deletions(-) diff --git a/notmuch-client.h b/notmuch-client.h index f59b3965..e8fb0323 100644 --- a/notmuch-client.h +++ b/notmuch-client.h @@ -171,46 +171,46 @@ void notmuch_exit_if_unsupported_format (void); int -notmuch_count_command (notmuch_config_t *config, int argc, char *argv[]); +notmuch_count_command (notmuch_config_t *config, notmuch_database_t *notmuch, int argc, char *argv[]); int -notmuch_dump_command (notmuch_config_t *config, int argc, char *argv[]); +notmuch_dump_command (notmuch_config_t *config, notmuch_database_t *notmuch, int argc, char *argv[]); int -notmuch_new_command (notmuch_config_t *config, int argc, char *argv[]); +notmuch_new_command (notmuch_config_t *config, notmuch_database_t *notmuch, int argc, char *argv[]); int -notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[]); +notmuch_insert_command (notmuch_config_t *config, notmuch_database_t *notmuch, int argc, char *argv[]); int -notmuch_reindex_command (notmuch_config_t *config, int argc, char *argv[]); +notmuch_reindex_command (notmuch_config_t *config, notmuch_database_t *notmuch, int argc, char *argv[]); int -notmuch_reply_command (notmuch_config_t *config, int argc, char *argv[]); +notmuch_reply_command (notmuch_config_t *config, notmuch_database_t *notmuch, int argc, char *argv[]); int -notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[]); +notmuch_restore_command (notmuch_config_t *config, notmuch_database_t *notmuch, int argc, char *argv[]); int -notmuch_search_command (notmuch_config_t *config, int argc, char *argv[]); +notmuch_search_command (notmuch_config_t *config, notmuch_database_t *notmuch, int argc, char *argv[]); int -notmuch_address_command (notmuch_config_t *config, int argc, char *argv[]); +notmuch_address_command (notmuch_config_t *config, notmuch_database_t *notmuch, int argc, char *argv[]); int -notmuch_setup_command (notmuch_config_t *config, int argc, char *argv[]); +notmuch_setup_command (notmuch_config_t *config, notmuch_database_t *notmuch, int argc, char *argv[]); int -notmuch_show_command (notmuch_config_t *config, int argc, char *argv[]); +notmuch_show_command (notmuch_config_t *config, notmuch_database_t *notmuch, int argc, char *argv[]); int -notmuch_tag_command (notmuch_config_t *config, int argc, char *argv[]); +notmuch_tag_command (notmuch_config_t *config, notmuch_database_t *notmuch, int argc, char *argv[]); int -notmuch_config_command (notmuch_config_t *config, int argc, char *argv[]); +notmuch_config_command (notmuch_config_t *config, notmuch_database_t *notmuch, int argc, char *argv[]); int -notmuch_compact_command (notmuch_config_t *config, int argc, char *argv[]); +notmuch_compact_command (notmuch_config_t *config, notmuch_database_t *notmuch, int argc, char *argv[]); const char * notmuch_time_relative_date (const void *ctx, time_t then); diff --git a/notmuch-compact.c b/notmuch-compact.c index f8996cf4..ab2066e1 100644 --- a/notmuch-compact.c +++ b/notmuch-compact.c @@ -27,7 +27,7 @@ status_update_cb (const char *msg, unused (void *closure)) } int -notmuch_compact_command (notmuch_config_t *config, int argc, char *argv[]) +notmuch_compact_command (notmuch_config_t *config, unused(notmuch_database_t *notmuch), int argc, char *argv[]) { const char *path = notmuch_config_get_database_path (config); const char *backup_path = NULL; diff --git a/notmuch-config.c b/notmuch-config.c index cefb8274..4fa274c7 100644 --- a/notmuch-config.c +++ b/notmuch-config.c @@ -1102,7 +1102,7 @@ notmuch_config_command_list (notmuch_config_t *config) } int -notmuch_config_command (notmuch_config_t *config, int argc, char *argv[]) +notmuch_config_command (notmuch_config_t *config, unused(notmuch_database_t *notmuch), int argc, char *argv[]) { int ret; int opt_index; diff --git a/notmuch-count.c b/notmuch-count.c index d8ad7d6d..f752ef62 100644 --- a/notmuch-count.c +++ b/notmuch-count.c @@ -148,7 +148,7 @@ count_file (notmuch_database_t *notmuch, FILE *input, const char **exclude_tags, } int -notmuch_count_command (notmuch_config_t *config, int argc, char *argv[]) +notmuch_count_command (notmuch_config_t *config, unused(notmuch_database_t *notmuch), int argc, char *argv[]) { notmuch_database_t *notmuch; char *query_str; diff --git a/notmuch-dump.c b/notmuch-dump.c index 887ef7f0..eb629dc9 100644 --- a/notmuch-dump.c +++ b/notmuch-dump.c @@ -361,7 +361,7 @@ notmuch_database_dump (notmuch_database_t *notmuch, } int -notmuch_dump_command (notmuch_config_t *config, int argc, char *argv[]) +notmuch_dump_command (notmuch_config_t *config, unused(notmuch_database_t *notmuch), int argc, char *argv[]) { notmuch_database_t *notmuch; const char *query_str = NULL; diff --git a/notmuch-insert.c b/notmuch-insert.c index 1d3b0150..de160309 100644 --- a/notmuch-insert.c +++ b/notmuch-insert.c @@ -444,7 +444,7 @@ add_file (notmuch_database_t *notmuch, const char *path, tag_op_list_t *tag_ops, } int -notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[]) +notmuch_insert_command (notmuch_config_t *config, unused(notmuch_database_t *notmuch), int argc, char *argv[]) { notmuch_status_t status, close_status; notmuch_database_t *notmuch; diff --git a/notmuch-new.c b/notmuch-new.c index 4075d395..e0e3de25 100644 --- a/notmuch-new.c +++ b/notmuch-new.c @@ -1043,7 +1043,7 @@ print_results (const add_files_state_t *state) } int -notmuch_new_command (notmuch_config_t *config, int argc, char *argv[]) +notmuch_new_command (notmuch_config_t *config, unused(notmuch_database_t *notmuch), int argc, char *argv[]) { notmuch_database_t *notmuch; add_files_state_t add_files_state = { diff --git a/notmuch-reindex.c b/notmuch-reindex.c index 5a39ade1..9d337c48 100644 --- a/notmuch-reindex.c +++ b/notmuch-reindex.c @@ -83,7 +83,7 @@ reindex_query (notmuch_database_t *notmuch, const char *query_string, } int -notmuch_reindex_command (notmuch_config_t *config, int argc, char *argv[]) +notmuch_reindex_command (notmuch_config_t *config, unused(notmuch_database_t *notmuch), int argc, char *argv[]) { char *query_string = NULL; notmuch_database_t *notmuch; diff --git a/notmuch-reply.c b/notmuch-reply.c index ceb4f39b..a8ffbf75 100644 --- a/notmuch-reply.c +++ b/notmuch-reply.c @@ -700,7 +700,7 @@ do_reply (notmuch_config_t *config, } int -notmuch_reply_command (notmuch_config_t *config, int argc, char *argv[]) +notmuch_reply_command (notmuch_config_t *config, unused(notmuch_database_t *notmuch), int argc, char *argv[]) { notmuch_database_t *notmuch; notmuch_query_t *query; diff --git a/notmuch-restore.c b/notmuch-restore.c index e2dc3d45..544f4228 100644 --- a/notmuch-restore.c +++ b/notmuch-restore.c @@ -219,7 +219,7 @@ parse_sup_line (void *ctx, char *line, } int -notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[]) +notmuch_restore_command (notmuch_config_t *config, unused(notmuch_database_t *notmuch), int argc, char *argv[]) { notmuch_database_t *notmuch; bool accumulate = false; diff --git a/notmuch-search.c b/notmuch-search.c index 2805d960..34e27058 100644 --- a/notmuch-search.c +++ b/notmuch-search.c @@ -805,7 +805,7 @@ static const notmuch_opt_desc_t common_options[] = { }; int -notmuch_search_command (notmuch_config_t *config, int argc, char *argv[]) +notmuch_search_command (notmuch_config_t *config, unused(notmuch_database_t *notmuch), int argc, char *argv[]) { search_context_t *ctx = &search_context; int opt_index, ret; @@ -871,7 +871,7 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[]) } int -notmuch_address_command (notmuch_config_t *config, int argc, char *argv[]) +notmuch_address_command (notmuch_config_t *config, unused(notmuch_database_t *notmuch), int argc, char *argv[]) { search_context_t *ctx = &search_context; int opt_index, ret; diff --git a/notmuch-setup.c b/notmuch-setup.c index cd1a52ff..67214470 100644 --- a/notmuch-setup.c +++ b/notmuch-setup.c @@ -122,6 +122,7 @@ parse_tag_list (void *ctx, char *response) int notmuch_setup_command (notmuch_config_t *config, + unused(notmuch_database_t *notmuch), int argc, char *argv[]) { char *response = NULL; diff --git a/notmuch-show.c b/notmuch-show.c index c0498c66..58623d00 100644 --- a/notmuch-show.c +++ b/notmuch-show.c @@ -1215,7 +1215,7 @@ static const notmuch_show_format_t *formatters[] = { }; int -notmuch_show_command (notmuch_config_t *config, int argc, char *argv[]) +notmuch_show_command (notmuch_config_t *config, unused(notmuch_database_t *notmuch), int argc, char *argv[]) { notmuch_database_t *notmuch; notmuch_query_t *query; diff --git a/notmuch-tag.c b/notmuch-tag.c index 05b1837d..205f2733 100644 --- a/notmuch-tag.c +++ b/notmuch-tag.c @@ -187,7 +187,7 @@ tag_file (void *ctx, notmuch_database_t *notmuch, tag_op_flag_t flags, } int -notmuch_tag_command (notmuch_config_t *config, int argc, char *argv[]) +notmuch_tag_command (notmuch_config_t *config, unused(notmuch_database_t *notmuch), int argc, char *argv[]) { tag_op_list_t *tag_ops = NULL; char *query_string = NULL; diff --git a/notmuch.c b/notmuch.c index 314bf53e..fd4a7945 100644 --- a/notmuch.c +++ b/notmuch.c @@ -27,8 +27,11 @@ * * The return value will be used as notmuch exit status code, * preferably EXIT_SUCCESS or EXIT_FAILURE. + * + * Each subcommand should be passed either a config object, or an open + * database */ -typedef int (*command_function_t) (notmuch_config_t *config, int argc, char *argv[]); +typedef int (*command_function_t) (notmuch_config_t *config, notmuch_database_t *notmuch, int argc, char *argv[]); typedef struct command { const char *name; @@ -38,10 +41,10 @@ typedef struct command { } command_t; static int -notmuch_help_command (notmuch_config_t *config, int argc, char *argv[]); +notmuch_help_command (notmuch_config_t *config, notmuch_database_t *notmuch, int argc, char *argv[]); static int -notmuch_command (notmuch_config_t *config, int argc, char *argv[]); +notmuch_command (notmuch_config_t *config, notmuch_database_t *notmuch, int argc, char *argv[]); static int _help_for (const char *topic); @@ -335,7 +338,7 @@ _help_for (const char *topic_name) } static int -notmuch_help_command (unused (notmuch_config_t *config), int argc, char *argv[]) +notmuch_help_command (unused (notmuch_config_t *config), unused(notmuch_database_t *notmuch), int argc, char *argv[]) { int opt_index; @@ -360,6 +363,7 @@ notmuch_help_command (unused (notmuch_config_t *config), int argc, char *argv[]) */ static int notmuch_command (notmuch_config_t *config, + unused(notmuch_database_t *notmuch), unused(int argc), unused(char **argv)) { char *db_path; @@ -369,7 +373,7 @@ notmuch_command (notmuch_config_t *config, * notmuch_setup_command which will give a nice welcome message, * and interactively guide the user through the configuration. */ if (notmuch_config_is_new (config)) - return notmuch_setup_command (config, 0, NULL); + return notmuch_setup_command (config, NULL, 0, NULL); /* Notmuch is already configured, but is there a database? */ db_path = talloc_asprintf (config, "%s/%s", @@ -502,7 +506,7 @@ main (int argc, char *argv[]) goto DONE; } - ret = (command->function)(config, argc - opt_index, argv + opt_index); + ret = (command->function)(config, NULL, argc - opt_index, argv + opt_index); DONE: if (config)