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
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
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
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
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
55 diff --git a/lib/notmuch.h b/lib/notmuch.h
\r
56 index 2faa146..927ea3c 100644
\r
59 @@ -927,6 +927,19 @@ notmuch_messages_t *
\r
60 notmuch_query_search_messages (notmuch_query_t *query);
\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
68 + * @param[in] query the query to collect tags for
\r
69 + * @param[out] out the return tags list
\r
73 +notmuch_query_search_tags (notmuch_query_t *query, notmuch_tags_t **out);
\r
76 * Destroy a notmuch_query_t along with any associated resources.
\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
83 @@ -310,6 +310,41 @@ _notmuch_query_search_documents (notmuch_query_t *query,
\r
88 +notmuch_query_search_tags (notmuch_query_t *query, notmuch_tags_t **tags)
\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
96 + return NOTMUCH_STATUS_NULL_POINTER;
\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
104 + notmuch_status_t status;
\r
105 + status = notmuch_query_search_messages_st (query, &messages);
\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
117 + notmuch_messages_destroy (messages);
\r
123 _notmuch_mset_messages_valid (notmuch_messages_t *messages)
\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
135 do_search_tags (const search_context_t *ctx)
\r
137 - notmuch_messages_t *messages = NULL;
\r
138 notmuch_tags_t *tags;
\r
140 sprinter_t *format = ctx->format;
\r
141 notmuch_query_t *query = ctx->query;
\r
142 - notmuch_database_t *notmuch = ctx->notmuch;
\r
144 - /* should the following only special case if no excluded terms
\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
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
156 - tags = notmuch_messages_collect_tags (messages);
\r
158 - if (tags == NULL)
\r
159 + if (print_status_query ("notmuch search",
\r
161 + notmuch_query_search_tags (query, &tags)))
\r
164 format->begin_list (format);
\r
165 @@ -653,9 +640,6 @@ do_search_tags (const search_context_t *ctx)
\r
167 notmuch_tags_destroy (tags);
\r
170 - notmuch_messages_destroy (messages);
\r
172 format->end (format);
\r