[PATCH 3/3] cli: convert remainder of CLI to n_q_search_{messages,threads}_st
[notmuch-archives.git] / c4 / 7f979c81ff04a23237f692132ffbb1efe607fb
1 Return-Path: <bremner@tethera.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 arlo.cworth.org (Postfix) with ESMTP id 275F86DE1636\r
6  for <notmuch@notmuchmail.org>; Sun,  6 Sep 2015 06:58:46 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at cworth.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: 2.65\r
10 X-Spam-Level: **\r
11 X-Spam-Status: No, score=2.65 tagged_above=-999 required=5 tests=[AWL=-1.040, \r
12  RCVD_IN_BRBL_LASTEXT=1.644, RCVD_IN_SBL=2.596,\r
13  RP_MATCHES_RCVD=-0.55] autolearn=disabled\r
14 Received: from arlo.cworth.org ([127.0.0.1])\r
15  by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)\r
16  with ESMTP id Dxb4x7nrvGp0 for <notmuch@notmuchmail.org>;\r
17  Sun,  6 Sep 2015 06:58:44 -0700 (PDT)\r
18 Received: from yantan.tethera.net (yantan.tethera.net [199.188.72.155])\r
19  by arlo.cworth.org (Postfix) with ESMTPS id 57A9A6DE163F\r
20  for <notmuch@notmuchmail.org>; Sun,  6 Sep 2015 06:58:44 -0700 (PDT)\r
21 Received: from remotemail by yantan.tethera.net with local (Exim 4.80)\r
22  (envelope-from <bremner@tethera.net>)\r
23  id 1ZYZna-0002xJ-Iv; Sun, 06 Sep 2015 10:15:58 -0300\r
24 Received: (nullmailer pid 29730 invoked by uid 1000); Sun, 06 Sep 2015\r
25  13:15:48 -0000\r
26 From: David Bremner <david@tethera.net>\r
27 To: notmuch@notmuchmail.org\r
28 Subject: [PATCH 3/3] cli: convert remainder of CLI to\r
29  n_q_search_{messages,threads}_st\r
30 Date: Sun,  6 Sep 2015 10:15:47 -0300\r
31 Message-Id: <1441545347-29549-3-git-send-email-david@tethera.net>\r
32 X-Mailer: git-send-email 2.5.1\r
33 In-Reply-To: <1441545347-29549-1-git-send-email-david@tethera.net>\r
34 References: <1441545347-29549-1-git-send-email-david@tethera.net>\r
35 X-BeenThere: notmuch@notmuchmail.org\r
36 X-Mailman-Version: 2.1.18\r
37 Precedence: list\r
38 List-Id: "Use and development of the notmuch mail system."\r
39  <notmuch.notmuchmail.org>\r
40 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
41  <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
42 List-Archive: <http://notmuchmail.org/pipermail/notmuch/>\r
43 List-Post: <mailto:notmuch@notmuchmail.org>\r
44 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
45 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
46  <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
47 X-List-Received-Date: Sun, 06 Sep 2015 13:58:46 -0000\r
48 \r
49 I think it would be no real problem to cut and paste the gdb based\r
50 error message test from count to the other clients modified here, but\r
51 I'm not currently convinced it's worth the trouble since the code path\r
52 being tested is almost the the same, and the tests are relatively\r
53 heavyweight.\r
54 ---\r
55  notmuch-dump.c   |  7 ++++++-\r
56  notmuch-reply.c  | 20 +++++++++++++++++---\r
57  notmuch-search.c | 15 +++++++++------\r
58  notmuch-show.c   | 10 +++++++---\r
59  notmuch-tag.c    |  8 +++++++-\r
60  5 files changed, 46 insertions(+), 14 deletions(-)\r
61 \r
62 diff --git a/notmuch-dump.c b/notmuch-dump.c\r
63 index 24fc2f2..829781f 100644\r
64 --- a/notmuch-dump.c\r
65 +++ b/notmuch-dump.c\r
66 @@ -48,8 +48,13 @@ database_dump_file (notmuch_database_t *notmuch, gzFile output,\r
67  \r
68      char *buffer = NULL;\r
69      size_t buffer_size = 0;\r
70 +    notmuch_status_t status;\r
71  \r
72 -    for (messages = notmuch_query_search_messages (query);\r
73 +    status = notmuch_query_search_messages_st (query, &messages);\r
74 +    if (print_status_query ("notmuch dump", query, status))\r
75 +       return EXIT_FAILURE;\r
76 +\r
77 +    for (;\r
78          notmuch_messages_valid (messages);\r
79          notmuch_messages_move_to_next (messages)) {\r
80         int first = 1;\r
81 diff --git a/notmuch-reply.c b/notmuch-reply.c\r
82 index 7c5c28f..fd6a1ec 100644\r
83 --- a/notmuch-reply.c\r
84 +++ b/notmuch-reply.c\r
85 @@ -606,8 +606,13 @@ notmuch_reply_format_default(void *ctx,\r
86      notmuch_messages_t *messages;\r
87      notmuch_message_t *message;\r
88      mime_node_t *root;\r
89 +    notmuch_status_t status;\r
90  \r
91 -    for (messages = notmuch_query_search_messages (query);\r
92 +    status = notmuch_query_search_messages_st (query, &messages);\r
93 +    if (print_status_query ("notmuch reply", query, status))\r
94 +       return 1;\r
95 +\r
96 +    for (;\r
97          notmuch_messages_valid (messages);\r
98          notmuch_messages_move_to_next (messages))\r
99      {\r
100 @@ -650,13 +655,17 @@ notmuch_reply_format_sprinter(void *ctx,\r
101      notmuch_messages_t *messages;\r
102      notmuch_message_t *message;\r
103      mime_node_t *node;\r
104 +    notmuch_status_t status;\r
105  \r
106      if (notmuch_query_count_messages (query) != 1) {\r
107         fprintf (stderr, "Error: search term did not match precisely one message.\n");\r
108         return 1;\r
109      }\r
110  \r
111 -    messages = notmuch_query_search_messages (query);\r
112 +    status = notmuch_query_search_messages_st (query, &messages);\r
113 +    if (print_status_query ("notmuch reply", query, status))\r
114 +       return 1;\r
115 +\r
116      message = notmuch_messages_get (messages);\r
117      if (mime_node_open (ctx, message, &(params->crypto), &node) != NOTMUCH_STATUS_SUCCESS)\r
118         return 1;\r
119 @@ -698,8 +707,13 @@ notmuch_reply_format_headers_only(void *ctx,\r
120      notmuch_message_t *message;\r
121      const char *in_reply_to, *orig_references, *references;\r
122      char *reply_headers;\r
123 +    notmuch_status_t status;\r
124 +\r
125 +    status = notmuch_query_search_messages_st (query, &messages);\r
126 +    if (print_status_query ("notmuch reply", query, status))\r
127 +       return 1;\r
128  \r
129 -    for (messages = notmuch_query_search_messages (query);\r
130 +    for (;\r
131          notmuch_messages_valid (messages);\r
132          notmuch_messages_move_to_next (messages))\r
133      {\r
134 diff --git a/notmuch-search.c b/notmuch-search.c\r
135 index 3076c3f..bade114 100644\r
136 --- a/notmuch-search.c\r
137 +++ b/notmuch-search.c\r
138 @@ -111,6 +111,7 @@ do_search_threads (search_context_t *ctx)\r
139      sprinter_t *format = ctx->format;\r
140      time_t date;\r
141      int i;\r
142 +    notmuch_status_t status;\r
143  \r
144      if (ctx->offset < 0) {\r
145         ctx->offset += notmuch_query_count_threads (ctx->query);\r
146 @@ -118,8 +119,8 @@ do_search_threads (search_context_t *ctx)\r
147             ctx->offset = 0;\r
148      }\r
149  \r
150 -    threads = notmuch_query_search_threads (ctx->query);\r
151 -    if (threads == NULL)\r
152 +    status = notmuch_query_search_threads_st (ctx->query, &threads);\r
153 +    if (print_status_query("notmuch search", ctx->query, status))\r
154         return 1;\r
155  \r
156      format->begin_list (format);\r
157 @@ -412,6 +413,7 @@ do_search_messages (search_context_t *ctx)\r
158      notmuch_filenames_t *filenames;\r
159      sprinter_t *format = ctx->format;\r
160      int i;\r
161 +    notmuch_status_t status;\r
162  \r
163      if (ctx->offset < 0) {\r
164         ctx->offset += notmuch_query_count_messages (ctx->query);\r
165 @@ -419,8 +421,8 @@ do_search_messages (search_context_t *ctx)\r
166             ctx->offset = 0;\r
167      }\r
168  \r
169 -    messages = notmuch_query_search_messages (ctx->query);\r
170 -    if (messages == NULL)\r
171 +    status = notmuch_query_search_messages_st (ctx->query, &messages);\r
172 +    if (print_status_query ("notmuch search", ctx->query, status))\r
173         return 1;\r
174  \r
175      format->begin_list (format);\r
176 @@ -508,8 +510,9 @@ do_search_tags (const search_context_t *ctx)\r
177      if (strcmp (notmuch_query_get_query_string (query), "*") == 0) {\r
178         tags = notmuch_database_get_all_tags (notmuch);\r
179      } else {\r
180 -       messages = notmuch_query_search_messages (query);\r
181 -       if (messages == NULL)\r
182 +       notmuch_status_t status;\r
183 +       status = notmuch_query_search_messages_st (query, &messages);\r
184 +       if (print_status_query ("notmuch search", query, status))\r
185             return 1;\r
186  \r
187         tags = notmuch_messages_collect_tags (messages);\r
188 diff --git a/notmuch-show.c b/notmuch-show.c\r
189 index 4356025..e054808 100644\r
190 --- a/notmuch-show.c\r
191 +++ b/notmuch-show.c\r
192 @@ -895,13 +895,17 @@ do_show_single (void *ctx,\r
193  {\r
194      notmuch_messages_t *messages;\r
195      notmuch_message_t *message;\r
196 +    notmuch_status_t status;\r
197  \r
198      if (notmuch_query_count_messages (query) != 1) {\r
199         fprintf (stderr, "Error: search term did not match precisely one message.\n");\r
200         return 1;\r
201      }\r
202  \r
203 -    messages = notmuch_query_search_messages (query);\r
204 +    status = notmuch_query_search_messages_st (query, &messages);\r
205 +    if (print_status_query ("notmuch show", query, status))\r
206 +       return 1;\r
207 +\r
208      message = notmuch_messages_get (messages);\r
209  \r
210      if (message == NULL) {\r
211 @@ -928,8 +932,8 @@ do_show (void *ctx,\r
212      notmuch_messages_t *messages;\r
213      notmuch_status_t status, res = NOTMUCH_STATUS_SUCCESS;\r
214  \r
215 -    threads = notmuch_query_search_threads (query);\r
216 -    if (! threads)\r
217 +    status= notmuch_query_search_threads_st (query, &threads);\r
218 +    if (print_status_query ("notmuch show", query, status))\r
219         return 1;\r
220  \r
221      sp->begin_list (sp);\r
222 diff --git a/notmuch-tag.c b/notmuch-tag.c\r
223 index 7ae98f6..c020cb6 100644\r
224 --- a/notmuch-tag.c\r
225 +++ b/notmuch-tag.c\r
226 @@ -97,6 +97,8 @@ tag_query (void *ctx, notmuch_database_t *notmuch, const char *query_string,\r
227      notmuch_query_t *query;\r
228      notmuch_messages_t *messages;\r
229      notmuch_message_t *message;\r
230 +    notmuch_status_t status;\r
231 +\r
232      int ret = NOTMUCH_STATUS_SUCCESS;\r
233  \r
234      if (! (flags & TAG_FLAG_REMOVE_ALL)) {\r
235 @@ -119,7 +121,11 @@ tag_query (void *ctx, notmuch_database_t *notmuch, const char *query_string,\r
236      /* tagging is not interested in any special sort order */\r
237      notmuch_query_set_sort (query, NOTMUCH_SORT_UNSORTED);\r
238  \r
239 -    for (messages = notmuch_query_search_messages (query);\r
240 +    status = notmuch_query_search_messages_st (query, &messages);\r
241 +    if (print_status_query ("notmuch tag", query, status))\r
242 +       return status;\r
243 +\r
244 +    for (;\r
245          notmuch_messages_valid (messages) && ! interrupted;\r
246          notmuch_messages_move_to_next (messages)) {\r
247         message = notmuch_messages_get (messages);\r
248 -- \r
249 2.5.1\r
250 \r