From: David Edmondson Date: Fri, 2 May 2014 08:15:51 +0000 (+0100) Subject: [PATCH 1/5] notmuch-new: Use tag_op_list_apply() rather than hand-coding the same. X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=1ddd68806650c0b0da57284bb7424044af04e43a;p=notmuch-archives.git [PATCH 1/5] notmuch-new: Use tag_op_list_apply() rather than hand-coding the same. --- diff --git a/c0/062a2eb4d6a67266934c6d7cb703ebb90d7533 b/c0/062a2eb4d6a67266934c6d7cb703ebb90d7533 new file mode 100644 index 000000000..c1cc8385a --- /dev/null +++ b/c0/062a2eb4d6a67266934c6d7cb703ebb90d7533 @@ -0,0 +1,142 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by olra.theworths.org (Postfix) with ESMTP id 2DDF9429E34 + for ; Fri, 2 May 2014 01:23:33 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: 0.379 +X-Spam-Level: +X-Spam-Status: No, score=0.379 tagged_above=-999 required=5 + tests=[NO_DNS_FOR_FROM=0.379] autolearn=disabled +Received: from olra.theworths.org ([127.0.0.1]) + by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id p-mRLSGE+BAP for ; + Fri, 2 May 2014 01:23:28 -0700 (PDT) +Received: from disaster-area.hh.sledj.net (disaster-area.hh.sledj.net + [81.149.164.25]) + (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id 944F1431FCF + for ; Fri, 2 May 2014 01:23:17 -0700 (PDT) +Received: from hotblack-desiato.hh.sledj.net (hotblack-desiato.hh.sledj.net + [172.16.100.105]) + by disaster-area.hh.sledj.net (Postfix) with ESMTPSA id DB7825005F2; + Fri, 2 May 2014 09:16:11 +0100 (BST) +Received: by hotblack-desiato.hh.sledj.net (Postfix, from userid 30000) + id BC04E103453; Fri, 2 May 2014 09:16:10 +0100 (BST) +From: David Edmondson +To: notmuch@notmuchmail.org +Subject: [PATCH 1/5] notmuch-new: Use tag_op_list_apply() rather than + hand-coding the same. +Date: Fri, 2 May 2014 09:15:51 +0100 +Message-Id: <1399018555-1994-2-git-send-email-dme@dme.org> +X-Mailer: git-send-email 1.9.2 +In-Reply-To: <1399018555-1994-1-git-send-email-dme@dme.org> +References: <1399018555-1994-1-git-send-email-dme@dme.org> +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.13 +Precedence: list +List-Id: "Use and development of the notmuch mail system." + +List-Unsubscribe: , + +List-Archive: +List-Post: +List-Help: +List-Subscribe: , + +X-List-Received-Date: Fri, 02 May 2014 08:23:33 -0000 + +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 +