[PATCH 1/5] notmuch-new: Use tag_op_list_apply() rather than hand-coding the same.

David Edmondson dme at dme.org
Fri May 2 01:15:51 PDT 2014


Rather than hand-coding the application of tags to new messages, use
the existing tag_op_list_apply().
---
 notmuch-new.c | 31 ++++++++++++++++---------------
 1 file changed, 16 insertions(+), 15 deletions(-)

diff --git a/notmuch-new.c b/notmuch-new.c
index d269c7c..b53401a 100644
--- a/notmuch-new.c
+++ b/notmuch-new.c
@@ -45,10 +45,9 @@ typedef struct {
     int output_is_a_tty;
     enum verbosity verbosity;
     notmuch_bool_t debug;
-    const char **new_tags;
-    size_t new_tags_length;
     const char **new_ignore;
     size_t new_ignore_length;
+    tag_op_list_t *tag_ops;
 
     int total_files;
     int processed_files;
@@ -253,7 +252,6 @@ add_file (notmuch_database_t *notmuch, const char *filename,
 	  add_files_state_t *state)
 {
     notmuch_message_t *message = NULL;
-    const char **tag;
     notmuch_status_t status;
 
     status = notmuch_database_begin_atomic (notmuch);
@@ -263,14 +261,13 @@ add_file (notmuch_database_t *notmuch, const char *filename,
     status = notmuch_database_add_message (notmuch, filename, &message);
     switch (status) {
     /* Success. */
-    case NOTMUCH_STATUS_SUCCESS:
-	state->added_messages++;
-	notmuch_message_freeze (message);
-	for (tag = state->new_tags; *tag != NULL; tag++)
-	    notmuch_message_add_tag (message, *tag);
+    case NOTMUCH_STATUS_SUCCESS:;
+	tag_op_flag_t flags = 0;
+
 	if (state->synchronize_flags)
-	    notmuch_message_maildir_flags_to_tags (message);
-	notmuch_message_thaw (message);
+	    flags |= TAG_FLAG_MAILDIR_SYNC;
+	state->added_messages++;
+	(void) tag_op_list_apply (message, state->tag_ops, flags);
 	break;
     /* Non-fatal issues (go on to next file). */
     case NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID:
@@ -923,6 +920,8 @@ notmuch_new_command (notmuch_config_t *config, int argc, char *argv[])
     notmuch_bool_t timer_is_active = FALSE;
     notmuch_bool_t no_hooks = FALSE;
     notmuch_bool_t quiet = FALSE, verbose = FALSE;
+    const char **new_tags;
+    size_t new_tags_length;
 
     add_files_state.verbosity = VERBOSITY_NORMAL;
     add_files_state.debug = FALSE;
@@ -946,20 +945,22 @@ notmuch_new_command (notmuch_config_t *config, int argc, char *argv[])
     else if (verbose)
 	add_files_state.verbosity = VERBOSITY_VERBOSE;
 
-    add_files_state.new_tags = notmuch_config_get_new_tags (config, &add_files_state.new_tags_length);
+    new_tags = notmuch_config_get_new_tags (config, &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);
+    add_files_state.tag_ops = tag_op_list_create (config);
     db_path = notmuch_config_get_database_path (config);
 
-    for (i = 0; i < add_files_state.new_tags_length; i++) {
+    for (i = 0; i < new_tags_length; i++) {
 	const char *error_msg;
 
-	error_msg = illegal_tag (add_files_state.new_tags[i], FALSE);
+	error_msg = illegal_tag (new_tags[i], FALSE);
 	if (error_msg) {
-	    fprintf (stderr, "Error: tag '%s' in new.tags: %s\n",
-		     add_files_state.new_tags[i], error_msg);
+	    fprintf (stderr, "Error: tag '%s' in new.tags: %s\n", new_tags[i], error_msg);
 	    return EXIT_FAILURE;
 	}
+	if (tag_op_list_append (add_files_state.tag_ops, new_tags[i], FALSE) != 0)
+	    return EXIT_FAILURE;
     }
 
     if (!no_hooks) {
-- 
1.9.2



More information about the notmuch mailing list