Re: [PATCH v4 01/16] add util/search-path.{c, h} to test for executables in $PATH
[notmuch-archives.git] / 09 / 9e43207133309968a0bffbade3899535d78623
1 Return-Path: <dme@hotblack-desiato.hh.sledj.net>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5         by olra.theworths.org (Postfix) with ESMTP id 8EABB429E34\r
6         for <notmuch@notmuchmail.org>; Fri,  2 May 2014 05:15:07 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: 0.379\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0.379 tagged_above=-999 required=5\r
12         tests=[NO_DNS_FOR_FROM=0.379] autolearn=disabled\r
13 Received: from olra.theworths.org ([127.0.0.1])\r
14         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
15         with ESMTP id Bg4jBL8POnFQ for <notmuch@notmuchmail.org>;\r
16         Fri,  2 May 2014 05:15:06 -0700 (PDT)\r
17 Received: from disaster-area.hh.sledj.net (disaster-area.hh.sledj.net\r
18         [81.149.164.25])\r
19         (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits))\r
20         (No client certificate requested)\r
21         by olra.theworths.org (Postfix) with ESMTPS id AAAAF431FD6\r
22         for <notmuch@notmuchmail.org>; Fri,  2 May 2014 05:14:59 -0700 (PDT)\r
23 Received: from hotblack-desiato.hh.sledj.net (hotblack-desiato.hh.sledj.net\r
24         [172.16.100.105])\r
25         by disaster-area.hh.sledj.net (Postfix) with ESMTPSA id 10F1E5012F1;\r
26         Fri,  2 May 2014 13:14:57 +0100 (BST)\r
27 Received: by hotblack-desiato.hh.sledj.net (Postfix, from userid 30000)\r
28         id A713910345B; Fri,  2 May 2014 13:14:56 +0100 (BST)\r
29 From: David Edmondson <dme@dme.org>\r
30 To: notmuch@notmuchmail.org\r
31 Subject: [PATCH 1/5] notmuch-new: Use tag_op_list_apply() rather than\r
32         hand-coding the same.\r
33 Date: Fri,  2 May 2014 13:14:43 +0100\r
34 Message-Id: <1399032887-25896-1-git-send-email-dme@dme.org>\r
35 X-Mailer: git-send-email 1.9.2\r
36 In-Reply-To: <cuniopogz2l.fsf@hotblack-desiato.hh.sledj.net>\r
37 References: <cuniopogz2l.fsf@hotblack-desiato.hh.sledj.net>\r
38 X-BeenThere: notmuch@notmuchmail.org\r
39 X-Mailman-Version: 2.1.13\r
40 Precedence: list\r
41 List-Id: "Use and development of the notmuch mail system."\r
42         <notmuch.notmuchmail.org>\r
43 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
44         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
45 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
46 List-Post: <mailto:notmuch@notmuchmail.org>\r
47 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
48 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
49         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
50 X-List-Received-Date: Fri, 02 May 2014 12:15:07 -0000\r
51 \r
52 Rather than hand-coding the application of tags to new messages, use\r
53 the existing tag_op_list_apply().\r
54 fixup.\r
55 ---\r
56  notmuch-new.c | 31 ++++++++++++++++---------------\r
57  tag-util.c    |  8 ++++++++\r
58  tag-util.h    | 10 +++++++---\r
59  3 files changed, 31 insertions(+), 18 deletions(-)\r
60 \r
61 diff --git a/notmuch-new.c b/notmuch-new.c\r
62 index d269c7c..2c3d680 100644\r
63 --- a/notmuch-new.c\r
64 +++ b/notmuch-new.c\r
65 @@ -45,10 +45,9 @@ typedef struct {\r
66      int output_is_a_tty;\r
67      enum verbosity verbosity;\r
68      notmuch_bool_t debug;\r
69 -    const char **new_tags;\r
70 -    size_t new_tags_length;\r
71      const char **new_ignore;\r
72      size_t new_ignore_length;\r
73 +    tag_op_list_t *tag_ops;\r
74  \r
75      int total_files;\r
76      int processed_files;\r
77 @@ -253,7 +252,6 @@ add_file (notmuch_database_t *notmuch, const char *filename,\r
78           add_files_state_t *state)\r
79  {\r
80      notmuch_message_t *message = NULL;\r
81 -    const char **tag;\r
82      notmuch_status_t status;\r
83  \r
84      status = notmuch_database_begin_atomic (notmuch);\r
85 @@ -263,14 +261,13 @@ add_file (notmuch_database_t *notmuch, const char *filename,\r
86      status = notmuch_database_add_message (notmuch, filename, &message);\r
87      switch (status) {\r
88      /* Success. */\r
89 -    case NOTMUCH_STATUS_SUCCESS:\r
90 -       state->added_messages++;\r
91 -       notmuch_message_freeze (message);\r
92 -       for (tag = state->new_tags; *tag != NULL; tag++)\r
93 -           notmuch_message_add_tag (message, *tag);\r
94 +    case NOTMUCH_STATUS_SUCCESS:;\r
95 +       tag_op_flag_t flags = 0;\r
96 +\r
97         if (state->synchronize_flags)\r
98 -           notmuch_message_maildir_flags_to_tags (message);\r
99 -       notmuch_message_thaw (message);\r
100 +           flags |= TAG_FLAG_TAG_SYNC;\r
101 +       state->added_messages++;\r
102 +       (void) tag_op_list_apply (message, state->tag_ops, flags);\r
103         break;\r
104      /* Non-fatal issues (go on to next file). */\r
105      case NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID:\r
106 @@ -923,6 +920,8 @@ notmuch_new_command (notmuch_config_t *config, int argc, char *argv[])\r
107      notmuch_bool_t timer_is_active = FALSE;\r
108      notmuch_bool_t no_hooks = FALSE;\r
109      notmuch_bool_t quiet = FALSE, verbose = FALSE;\r
110 +    const char **new_tags;\r
111 +    size_t new_tags_length;\r
112  \r
113      add_files_state.verbosity = VERBOSITY_NORMAL;\r
114      add_files_state.debug = FALSE;\r
115 @@ -946,20 +945,22 @@ notmuch_new_command (notmuch_config_t *config, int argc, char *argv[])\r
116      else if (verbose)\r
117         add_files_state.verbosity = VERBOSITY_VERBOSE;\r
118  \r
119 -    add_files_state.new_tags = notmuch_config_get_new_tags (config, &add_files_state.new_tags_length);\r
120 +    new_tags = notmuch_config_get_new_tags (config, &new_tags_length);\r
121      add_files_state.new_ignore = notmuch_config_get_new_ignore (config, &add_files_state.new_ignore_length);\r
122      add_files_state.synchronize_flags = notmuch_config_get_maildir_synchronize_flags (config);\r
123 +    add_files_state.tag_ops = tag_op_list_create (config);\r
124      db_path = notmuch_config_get_database_path (config);\r
125  \r
126 -    for (i = 0; i < add_files_state.new_tags_length; i++) {\r
127 +    for (i = 0; i < new_tags_length; i++) {\r
128         const char *error_msg;\r
129  \r
130 -       error_msg = illegal_tag (add_files_state.new_tags[i], FALSE);\r
131 +       error_msg = illegal_tag (new_tags[i], FALSE);\r
132         if (error_msg) {\r
133 -           fprintf (stderr, "Error: tag '%s' in new.tags: %s\n",\r
134 -                    add_files_state.new_tags[i], error_msg);\r
135 +           fprintf (stderr, "Error: tag '%s' in new.tags: %s\n", new_tags[i], error_msg);\r
136             return EXIT_FAILURE;\r
137         }\r
138 +       if (tag_op_list_append (add_files_state.tag_ops, new_tags[i], FALSE) != 0)\r
139 +           return EXIT_FAILURE;\r
140      }\r
141  \r
142      if (!no_hooks) {\r
143 diff --git a/tag-util.c b/tag-util.c\r
144 index 343c161..1dee2f3 100644\r
145 --- a/tag-util.c\r
146 +++ b/tag-util.c\r
147 @@ -327,6 +327,14 @@ tag_op_list_apply (notmuch_message_t *message,\r
148         }\r
149      }\r
150  \r
151 +    if (flags & TAG_FLAG_TAG_SYNC) {\r
152 +       status = notmuch_message_maildir_flags_to_tags (message);\r
153 +       if (status) {\r
154 +           message_error (message, status, "synching maildir to tags");\r
155 +           return status;\r
156 +       }\r
157 +    }\r
158 +\r
159      return NOTMUCH_STATUS_SUCCESS;\r
160  \r
161  }\r
162 diff --git a/tag-util.h b/tag-util.h\r
163 index 8a4074c..512cfac 100644\r
164 --- a/tag-util.h\r
165 +++ b/tag-util.h\r
166 @@ -14,19 +14,23 @@ typedef enum {\r
167       */\r
168      TAG_FLAG_MAILDIR_SYNC = (1 << 0),\r
169  \r
170 +    /* Operations are synced from maildir, if possible.\r
171 +     */\r
172 +    TAG_FLAG_TAG_SYNC = (1 << 1),\r
173 +\r
174      /* Remove all tags from message before applying list.\r
175       */\r
176 -    TAG_FLAG_REMOVE_ALL = (1 << 1),\r
177 +    TAG_FLAG_REMOVE_ALL = (1 << 2),\r
178  \r
179      /* Don't try to avoid database operations. Useful when we\r
180       * know that message passed needs these operations.\r
181       */\r
182 -    TAG_FLAG_PRE_OPTIMIZED = (1 << 2),\r
183 +    TAG_FLAG_PRE_OPTIMIZED = (1 << 3),\r
184  \r
185      /* Accept strange tags that might be user error;\r
186       * intended for use by notmuch-restore.\r
187       */\r
188 -    TAG_FLAG_BE_GENEROUS = (1 << 3)\r
189 +    TAG_FLAG_BE_GENEROUS = (1 << 4)\r
190  \r
191  } tag_op_flag_t;\r
192  \r
193 -- \r
194 1.9.2\r
195 \r