Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / 5c / d6658e58290befafa09269adb584ced92c15a3
1 Return-Path: <bremner@tesseract.cs.unb.ca>\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 211106DE01BA\r
6  for <notmuch@notmuchmail.org>; Thu, 30 Jun 2016 01:40:47 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at cworth.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -0.005\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.005 tagged_above=-999 required=5\r
12  tests=[AWL=-0.006, HEADER_FROM_DIFFERENT_DOMAINS=0.001]\r
13  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 tkfA5gYg-LGq for <notmuch@notmuchmail.org>;\r
17  Thu, 30 Jun 2016 01:40:39 -0700 (PDT)\r
18 Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197])\r
19  by arlo.cworth.org (Postfix) with ESMTPS id 156186DE00C9\r
20  for <notmuch@notmuchmail.org>; Thu, 30 Jun 2016 01:40:39 -0700 (PDT)\r
21 Received: from remotemail by fethera.tethera.net with local (Exim 4.84)\r
22  (envelope-from <bremner@tesseract.cs.unb.ca>)\r
23  id 1bIXWF-0007e8-Sm; Thu, 30 Jun 2016 04:40:19 -0400\r
24 Received: (nullmailer pid 30882 invoked by uid 1000);\r
25  Thu, 30 Jun 2016 08:40:30 -0000\r
26 From: David Bremner <david@tethera.net>\r
27 To: David Bremner <david@tethera.net>, notmuch@notmuchmail.org\r
28 Subject: [PATCH 1/2] WIP: refactor tag search into library routine\r
29 Date: Thu, 30 Jun 2016 10:40:26 +0200\r
30 Message-Id: <1467276027-30633-2-git-send-email-david@tethera.net>\r
31 X-Mailer: git-send-email 2.8.1\r
32 In-Reply-To: <1467276027-30633-1-git-send-email-david@tethera.net>\r
33 References: <87fustdsx9.fsf@zancas.localnet>\r
34  <1467276027-30633-1-git-send-email-david@tethera.net>\r
35 X-BeenThere: notmuch@notmuchmail.org\r
36 X-Mailman-Version: 2.1.20\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: <https://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: <https://notmuchmail.org/mailman/listinfo/notmuch>,\r
46  <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
47 X-List-Received-Date: Thu, 30 Jun 2016 08:40:47 -0000\r
48 \r
49 ---\r
50  lib/notmuch.h    | 13 +++++++++++++\r
51  lib/query.cc     | 35 +++++++++++++++++++++++++++++++++++\r
52  notmuch-search.c | 24 ++++--------------------\r
53  3 files changed, 52 insertions(+), 20 deletions(-)\r
54 \r
55 diff --git a/lib/notmuch.h b/lib/notmuch.h\r
56 index 2faa146..927ea3c 100644\r
57 --- a/lib/notmuch.h\r
58 +++ b/lib/notmuch.h\r
59 @@ -927,6 +927,19 @@ notmuch_messages_t *\r
60  notmuch_query_search_messages (notmuch_query_t *query);\r
61  \r
62  /**\r
63 + * Execute a query for tags, outputing a notmuch_tags_t object\r
64 + * which can be used to iterate over the results. The output\r
65 + * tags object is owned by the query and as such, will only be\r
66 + * valid until notmuch_query_destroy.\r
67 + *\r
68 + * @param[in] query   the query to collect tags for\r
69 + * @param[out] out    the return tags list\r
70 + *\r
71 + */\r
72 +notmuch_status_t\r
73 +notmuch_query_search_tags (notmuch_query_t *query, notmuch_tags_t **out);\r
74 +\r
75 +/**\r
76   * Destroy a notmuch_query_t along with any associated resources.\r
77   *\r
78   * This will in turn destroy any notmuch_threads_t and\r
79 diff --git a/lib/query.cc b/lib/query.cc\r
80 index 7eb73a1..7245b12 100644\r
81 --- a/lib/query.cc\r
82 +++ b/lib/query.cc\r
83 @@ -310,6 +310,41 @@ _notmuch_query_search_documents (notmuch_query_t *query,\r
84      }\r
85  }\r
86  \r
87 +notmuch_status_t\r
88 +notmuch_query_search_tags  (notmuch_query_t *query, notmuch_tags_t **tags)\r
89 +{\r
90 +    notmuch_messages_t *messages = NULL;\r
91 +    notmuch_database_t *notmuch = notmuch_query_get_database (query);\r
92 +    notmuch_status_t status = NOTMUCH_STATUS_SUCCESS;\r
93 +    const char *query_string = notmuch_query_get_query_string (query);\r
94 +\r
95 +    if (tags == NULL)\r
96 +       return NOTMUCH_STATUS_NULL_POINTER;\r
97 +\r
98 +    /* Special-case query of "*"  or '' for better performance. */\r
99 +    if (strcmp (query_string, "*") == 0 || *query_string == '\0') {\r
100 +       *tags = notmuch_database_get_all_tags (notmuch);\r
101 +       if (*tags == NULL)\r
102 +           status = NOTMUCH_STATUS_XAPIAN_EXCEPTION;\r
103 +    } else {\r
104 +       notmuch_status_t status;\r
105 +       status = notmuch_query_search_messages_st (query, &messages);\r
106 +       if (status)\r
107 +           goto DONE;\r
108 +\r
109 +       *tags = notmuch_messages_collect_tags (messages);\r
110 +       talloc_steal (query, *tags);\r
111 +       if (*tags == NULL)\r
112 +           status = NOTMUCH_STATUS_OUT_OF_MEMORY;\r
113 +    }\r
114 +\r
115 + DONE:\r
116 +    if (messages)\r
117 +       notmuch_messages_destroy (messages);\r
118 +\r
119 +    return status;\r
120 +}\r
121 +\r
122  notmuch_bool_t\r
123  _notmuch_mset_messages_valid (notmuch_messages_t *messages)\r
124  {\r
125 diff --git a/notmuch-search.c b/notmuch-search.c\r
126 index 8c65d5a..8722735 100644\r
127 --- a/notmuch-search.c\r
128 +++ b/notmuch-search.c\r
129 @@ -611,31 +611,18 @@ do_search_messages (search_context_t *ctx)\r
130      return 0;\r
131  }\r
132  \r
133 +\r
134  static int\r
135  do_search_tags (const search_context_t *ctx)\r
136  {\r
137 -    notmuch_messages_t *messages = NULL;\r
138      notmuch_tags_t *tags;\r
139      const char *tag;\r
140      sprinter_t *format = ctx->format;\r
141      notmuch_query_t *query = ctx->query;\r
142 -    notmuch_database_t *notmuch = ctx->notmuch;\r
143 -\r
144 -    /* should the following only special case if no excluded terms\r
145 -     * specified? */\r
146 -\r
147 -    /* Special-case query of "*" for better performance. */\r
148 -    if (strcmp (notmuch_query_get_query_string (query), "*") == 0) {\r
149 -       tags = notmuch_database_get_all_tags (notmuch);\r
150 -    } else {\r
151 -       notmuch_status_t status;\r
152 -       status = notmuch_query_search_messages_st (query, &messages);\r
153 -       if (print_status_query ("notmuch search", query, status))\r
154 -           return 1;\r
155  \r
156 -       tags = notmuch_messages_collect_tags (messages);\r
157 -    }\r
158 -    if (tags == NULL)\r
159 +    if (print_status_query ("notmuch search",\r
160 +                           query,\r
161 +                           notmuch_query_search_tags (query, &tags)))\r
162         return 1;\r
163  \r
164      format->begin_list (format);\r
165 @@ -653,9 +640,6 @@ do_search_tags (const search_context_t *ctx)\r
166  \r
167      notmuch_tags_destroy (tags);\r
168  \r
169 -    if (messages)\r
170 -       notmuch_messages_destroy (messages);\r
171 -\r
172      format->end (format);\r
173  \r
174      return 0;\r
175 -- \r
176 2.8.1\r
177 \r