From: David Edmondson <dme@dme.org>
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 13:14:43 +0100 [thread overview]
Message-ID: <1399032887-25896-1-git-send-email-dme@dme.org> (raw)
In-Reply-To: <cuniopogz2l.fsf@hotblack-desiato.hh.sledj.net>
Rather than hand-coding the application of tags to new messages, use
the existing tag_op_list_apply().
fixup.
---
notmuch-new.c | 31 ++++++++++++++++---------------
tag-util.c | 8 ++++++++
tag-util.h | 10 +++++++---
3 files changed, 31 insertions(+), 18 deletions(-)
diff --git a/notmuch-new.c b/notmuch-new.c
index d269c7c..2c3d680 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_TAG_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) {
diff --git a/tag-util.c b/tag-util.c
index 343c161..1dee2f3 100644
--- a/tag-util.c
+++ b/tag-util.c
@@ -327,6 +327,14 @@ tag_op_list_apply (notmuch_message_t *message,
}
}
+ if (flags & TAG_FLAG_TAG_SYNC) {
+ status = notmuch_message_maildir_flags_to_tags (message);
+ if (status) {
+ message_error (message, status, "synching maildir to tags");
+ return status;
+ }
+ }
+
return NOTMUCH_STATUS_SUCCESS;
}
diff --git a/tag-util.h b/tag-util.h
index 8a4074c..512cfac 100644
--- a/tag-util.h
+++ b/tag-util.h
@@ -14,19 +14,23 @@ typedef enum {
*/
TAG_FLAG_MAILDIR_SYNC = (1 << 0),
+ /* Operations are synced from maildir, if possible.
+ */
+ TAG_FLAG_TAG_SYNC = (1 << 1),
+
/* Remove all tags from message before applying list.
*/
- TAG_FLAG_REMOVE_ALL = (1 << 1),
+ TAG_FLAG_REMOVE_ALL = (1 << 2),
/* Don't try to avoid database operations. Useful when we
* know that message passed needs these operations.
*/
- TAG_FLAG_PRE_OPTIMIZED = (1 << 2),
+ TAG_FLAG_PRE_OPTIMIZED = (1 << 3),
/* Accept strange tags that might be user error;
* intended for use by notmuch-restore.
*/
- TAG_FLAG_BE_GENEROUS = (1 << 3)
+ TAG_FLAG_BE_GENEROUS = (1 << 4)
} tag_op_flag_t;
--
1.9.2
next prev parent reply other threads:[~2014-05-02 12:15 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-02 8:15 Add support for specifying tags during "notmuch new" David Edmondson
2014-05-02 8:15 ` [PATCH 1/5] notmuch-new: Use tag_op_list_apply() rather than hand-coding the same David Edmondson
2014-05-02 8:15 ` [PATCH 2/5] notmuch-new: Allow the tags of new messages to be manipulated David Edmondson
2014-05-02 8:15 ` [PATCH 3/5] notmuch-new: Manual: Add command line tags David Edmondson
2014-05-02 8:15 ` [PATCH 4/5] NEWS: Add information about "notmuch new" " David Edmondson
2014-05-02 8:15 ` [PATCH 5/5] Test: Add tests for " David Edmondson
2014-05-02 12:11 ` [PATCH v2 0/5] Add support for specifying tags during "notmuch new" David Edmondson
2014-05-02 12:14 ` David Edmondson [this message]
2014-05-02 12:14 ` [PATCH 2/5] notmuch-new: Allow the tags of new messages to be manipulated David Edmondson
2014-05-02 12:14 ` [PATCH 3/5] notmuch-new: Manual: Add command line tags David Edmondson
2014-05-02 12:14 ` [PATCH 4/5] NEWS: Add information about "notmuch new" " David Edmondson
2014-05-02 12:14 ` [PATCH 5/5] Test: Add tests for " David Edmondson
2014-05-02 14:07 ` [PATCH v2 0/5] Add support for specifying tags during "notmuch new" Mark Walters
2014-05-02 15:18 ` Austin Clements
2014-05-02 15:32 ` David Edmondson
2014-07-12 19:08 ` David Bremner
2014-07-13 3:40 ` Austin Clements
2014-07-13 11:58 ` David Bremner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://notmuchmail.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1399032887-25896-1-git-send-email-dme@dme.org \
--to=dme@dme.org \
--cc=notmuch@notmuchmail.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).