mirror of
https://git.notmuchmail.org/git/notmuch
synced 2024-11-24 11:58:10 +01:00
CLI: move indexopts variable out of shared options block
This reduces the amount of global state. Furthermore, index options can be set (in principle) in several ways, not just in the one function for processing indexing command line options.
This commit is contained in:
parent
c128c995bc
commit
2ce6c76a61
5 changed files with 18 additions and 16 deletions
|
@ -499,11 +499,10 @@ int notmuch_minimal_options (const char *subcommand_name,
|
||||||
struct _notmuch_client_indexing_cli_choices {
|
struct _notmuch_client_indexing_cli_choices {
|
||||||
int decrypt_policy;
|
int decrypt_policy;
|
||||||
bool decrypt_policy_set;
|
bool decrypt_policy_set;
|
||||||
notmuch_indexopts_t *opts;
|
|
||||||
};
|
};
|
||||||
extern struct _notmuch_client_indexing_cli_choices indexing_cli_choices;
|
extern struct _notmuch_client_indexing_cli_choices indexing_cli_choices;
|
||||||
extern const notmuch_opt_desc_t notmuch_shared_indexing_options [];
|
extern const notmuch_opt_desc_t notmuch_shared_indexing_options [];
|
||||||
notmuch_status_t
|
notmuch_status_t
|
||||||
notmuch_process_shared_indexing_options (notmuch_database_t *notmuch);
|
notmuch_process_shared_indexing_options (notmuch_indexopts_t *opts);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -461,6 +461,8 @@ notmuch_insert_command (notmuch_database_t *notmuch, int argc, char *argv[])
|
||||||
char *maildir;
|
char *maildir;
|
||||||
char *newpath;
|
char *newpath;
|
||||||
int opt_index;
|
int opt_index;
|
||||||
|
notmuch_indexopts_t *indexopts = notmuch_database_get_default_indexopts (notmuch);
|
||||||
|
|
||||||
void *local = talloc_new (NULL);
|
void *local = talloc_new (NULL);
|
||||||
|
|
||||||
notmuch_opt_desc_t options[] = {
|
notmuch_opt_desc_t options[] = {
|
||||||
|
@ -550,7 +552,7 @@ notmuch_insert_command (notmuch_database_t *notmuch, int argc, char *argv[])
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
status = notmuch_process_shared_indexing_options (notmuch);
|
status = notmuch_process_shared_indexing_options (indexopts);
|
||||||
if (status != NOTMUCH_STATUS_SUCCESS) {
|
if (status != NOTMUCH_STATUS_SUCCESS) {
|
||||||
fprintf (stderr, "Error: Failed to process index options. (%s)\n",
|
fprintf (stderr, "Error: Failed to process index options. (%s)\n",
|
||||||
notmuch_status_to_string (status));
|
notmuch_status_to_string (status));
|
||||||
|
@ -558,7 +560,7 @@ notmuch_insert_command (notmuch_database_t *notmuch, int argc, char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Index the message. */
|
/* Index the message. */
|
||||||
status = add_file (notmuch, newpath, tag_ops, synchronize_flags, keep, indexing_cli_choices.opts);
|
status = add_file (notmuch, newpath, tag_ops, synchronize_flags, keep, indexopts);
|
||||||
|
|
||||||
/* Commit changes. */
|
/* Commit changes. */
|
||||||
close_status = notmuch_database_close (notmuch);
|
close_status = notmuch_database_close (notmuch);
|
||||||
|
|
|
@ -45,6 +45,7 @@ typedef struct {
|
||||||
const char *db_path;
|
const char *db_path;
|
||||||
const char *mail_root;
|
const char *mail_root;
|
||||||
|
|
||||||
|
notmuch_indexopts_t *indexopts;
|
||||||
int output_is_a_tty;
|
int output_is_a_tty;
|
||||||
enum verbosity verbosity;
|
enum verbosity verbosity;
|
||||||
bool debug;
|
bool debug;
|
||||||
|
@ -376,7 +377,7 @@ add_file (notmuch_database_t *notmuch, const char *filename,
|
||||||
if (status)
|
if (status)
|
||||||
goto DONE;
|
goto DONE;
|
||||||
|
|
||||||
status = notmuch_database_index_file (notmuch, filename, indexing_cli_choices.opts, &message);
|
status = notmuch_database_index_file (notmuch, filename, state->indexopts, &message);
|
||||||
switch (status) {
|
switch (status) {
|
||||||
/* Success. */
|
/* Success. */
|
||||||
case NOTMUCH_STATUS_SUCCESS:
|
case NOTMUCH_STATUS_SUCCESS:
|
||||||
|
@ -1150,6 +1151,8 @@ notmuch_new_command (notmuch_database_t *notmuch, int argc, char *argv[])
|
||||||
else if (verbose)
|
else if (verbose)
|
||||||
add_files_state.verbosity = VERBOSITY_VERBOSE;
|
add_files_state.verbosity = VERBOSITY_VERBOSE;
|
||||||
|
|
||||||
|
add_files_state.indexopts = notmuch_database_get_default_indexopts (notmuch);
|
||||||
|
|
||||||
add_files_state.new_tags = notmuch_config_get_values (notmuch, NOTMUCH_CONFIG_NEW_TAGS);
|
add_files_state.new_tags = notmuch_config_get_values (notmuch, NOTMUCH_CONFIG_NEW_TAGS);
|
||||||
|
|
||||||
if (print_status_database (
|
if (print_status_database (
|
||||||
|
@ -1217,7 +1220,7 @@ notmuch_new_command (notmuch_database_t *notmuch, int argc, char *argv[])
|
||||||
if (notmuch == NULL)
|
if (notmuch == NULL)
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
|
|
||||||
status = notmuch_process_shared_indexing_options (notmuch);
|
status = notmuch_process_shared_indexing_options (add_files_state.indexopts);
|
||||||
if (status != NOTMUCH_STATUS_SUCCESS) {
|
if (status != NOTMUCH_STATUS_SUCCESS) {
|
||||||
fprintf (stderr, "Error: Failed to process index options. (%s)\n",
|
fprintf (stderr, "Error: Failed to process index options. (%s)\n",
|
||||||
notmuch_status_to_string (status));
|
notmuch_status_to_string (status));
|
||||||
|
|
|
@ -90,6 +90,7 @@ notmuch_reindex_command (notmuch_database_t *notmuch, int argc, char *argv[])
|
||||||
int opt_index;
|
int opt_index;
|
||||||
int ret;
|
int ret;
|
||||||
notmuch_status_t status;
|
notmuch_status_t status;
|
||||||
|
notmuch_indexopts_t *indexopts = notmuch_database_get_default_indexopts (notmuch);
|
||||||
|
|
||||||
/* Set up our handler for SIGINT */
|
/* Set up our handler for SIGINT */
|
||||||
memset (&action, 0, sizeof (struct sigaction));
|
memset (&action, 0, sizeof (struct sigaction));
|
||||||
|
@ -110,7 +111,7 @@ notmuch_reindex_command (notmuch_database_t *notmuch, int argc, char *argv[])
|
||||||
|
|
||||||
notmuch_process_shared_options (notmuch, argv[0]);
|
notmuch_process_shared_options (notmuch, argv[0]);
|
||||||
|
|
||||||
status = notmuch_process_shared_indexing_options (notmuch);
|
status = notmuch_process_shared_indexing_options (indexopts);
|
||||||
if (status != NOTMUCH_STATUS_SUCCESS) {
|
if (status != NOTMUCH_STATUS_SUCCESS) {
|
||||||
fprintf (stderr, "Error: Failed to process index options. (%s)\n",
|
fprintf (stderr, "Error: Failed to process index options. (%s)\n",
|
||||||
notmuch_status_to_string (status));
|
notmuch_status_to_string (status));
|
||||||
|
@ -128,7 +129,7 @@ notmuch_reindex_command (notmuch_database_t *notmuch, int argc, char *argv[])
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = reindex_query (notmuch, query_string, indexing_cli_choices.opts);
|
ret = reindex_query (notmuch, query_string, indexopts);
|
||||||
|
|
||||||
notmuch_database_destroy (notmuch);
|
notmuch_database_destroy (notmuch);
|
||||||
|
|
||||||
|
|
13
notmuch.c
13
notmuch.c
|
@ -141,21 +141,18 @@ const notmuch_opt_desc_t notmuch_shared_indexing_options [] = {
|
||||||
|
|
||||||
|
|
||||||
notmuch_status_t
|
notmuch_status_t
|
||||||
notmuch_process_shared_indexing_options (notmuch_database_t *notmuch)
|
notmuch_process_shared_indexing_options (notmuch_indexopts_t *opts)
|
||||||
{
|
{
|
||||||
if (indexing_cli_choices.opts == NULL)
|
if (opts == NULL)
|
||||||
indexing_cli_choices.opts = notmuch_database_get_default_indexopts (notmuch);
|
return NOTMUCH_STATUS_NULL_POINTER;
|
||||||
|
|
||||||
if (indexing_cli_choices.decrypt_policy_set) {
|
if (indexing_cli_choices.decrypt_policy_set) {
|
||||||
notmuch_status_t status;
|
notmuch_status_t status;
|
||||||
if (indexing_cli_choices.opts == NULL)
|
status = notmuch_indexopts_set_decrypt_policy (opts,
|
||||||
return NOTMUCH_STATUS_OUT_OF_MEMORY;
|
|
||||||
status = notmuch_indexopts_set_decrypt_policy (indexing_cli_choices.opts,
|
|
||||||
indexing_cli_choices.decrypt_policy);
|
indexing_cli_choices.decrypt_policy);
|
||||||
if (status != NOTMUCH_STATUS_SUCCESS) {
|
if (status != NOTMUCH_STATUS_SUCCESS) {
|
||||||
fprintf (stderr, "Error: Failed to set index decryption policy to %d. (%s)\n",
|
fprintf (stderr, "Error: Failed to set index decryption policy to %d. (%s)\n",
|
||||||
indexing_cli_choices.decrypt_policy, notmuch_status_to_string (status));
|
indexing_cli_choices.decrypt_policy, notmuch_status_to_string (status));
|
||||||
notmuch_indexopts_destroy (indexing_cli_choices.opts);
|
|
||||||
indexing_cli_choices.opts = NULL;
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue