From: David Bremner <david@tethera.net>
To: David Bremner <david@tethera.net>, notmuch@notmuchmail.org
Subject: [PATCH 1/2] WIP: refactor tag search into library routine
Date: Thu, 30 Jun 2016 10:40:26 +0200 [thread overview]
Message-ID: <1467276027-30633-2-git-send-email-david@tethera.net> (raw)
In-Reply-To: <1467276027-30633-1-git-send-email-david@tethera.net>
---
lib/notmuch.h | 13 +++++++++++++
lib/query.cc | 35 +++++++++++++++++++++++++++++++++++
notmuch-search.c | 24 ++++--------------------
3 files changed, 52 insertions(+), 20 deletions(-)
diff --git a/lib/notmuch.h b/lib/notmuch.h
index 2faa146..927ea3c 100644
--- a/lib/notmuch.h
+++ b/lib/notmuch.h
@@ -927,6 +927,19 @@ notmuch_messages_t *
notmuch_query_search_messages (notmuch_query_t *query);
/**
+ * Execute a query for tags, outputing a notmuch_tags_t object
+ * which can be used to iterate over the results. The output
+ * tags object is owned by the query and as such, will only be
+ * valid until notmuch_query_destroy.
+ *
+ * @param[in] query the query to collect tags for
+ * @param[out] out the return tags list
+ *
+ */
+notmuch_status_t
+notmuch_query_search_tags (notmuch_query_t *query, notmuch_tags_t **out);
+
+/**
* Destroy a notmuch_query_t along with any associated resources.
*
* This will in turn destroy any notmuch_threads_t and
diff --git a/lib/query.cc b/lib/query.cc
index 7eb73a1..7245b12 100644
--- a/lib/query.cc
+++ b/lib/query.cc
@@ -310,6 +310,41 @@ _notmuch_query_search_documents (notmuch_query_t *query,
}
}
+notmuch_status_t
+notmuch_query_search_tags (notmuch_query_t *query, notmuch_tags_t **tags)
+{
+ notmuch_messages_t *messages = NULL;
+ notmuch_database_t *notmuch = notmuch_query_get_database (query);
+ notmuch_status_t status = NOTMUCH_STATUS_SUCCESS;
+ const char *query_string = notmuch_query_get_query_string (query);
+
+ if (tags == NULL)
+ return NOTMUCH_STATUS_NULL_POINTER;
+
+ /* Special-case query of "*" or '' for better performance. */
+ if (strcmp (query_string, "*") == 0 || *query_string == '\0') {
+ *tags = notmuch_database_get_all_tags (notmuch);
+ if (*tags == NULL)
+ status = NOTMUCH_STATUS_XAPIAN_EXCEPTION;
+ } else {
+ notmuch_status_t status;
+ status = notmuch_query_search_messages_st (query, &messages);
+ if (status)
+ goto DONE;
+
+ *tags = notmuch_messages_collect_tags (messages);
+ talloc_steal (query, *tags);
+ if (*tags == NULL)
+ status = NOTMUCH_STATUS_OUT_OF_MEMORY;
+ }
+
+ DONE:
+ if (messages)
+ notmuch_messages_destroy (messages);
+
+ return status;
+}
+
notmuch_bool_t
_notmuch_mset_messages_valid (notmuch_messages_t *messages)
{
diff --git a/notmuch-search.c b/notmuch-search.c
index 8c65d5a..8722735 100644
--- a/notmuch-search.c
+++ b/notmuch-search.c
@@ -611,31 +611,18 @@ do_search_messages (search_context_t *ctx)
return 0;
}
+
static int
do_search_tags (const search_context_t *ctx)
{
- notmuch_messages_t *messages = NULL;
notmuch_tags_t *tags;
const char *tag;
sprinter_t *format = ctx->format;
notmuch_query_t *query = ctx->query;
- notmuch_database_t *notmuch = ctx->notmuch;
-
- /* should the following only special case if no excluded terms
- * specified? */
-
- /* Special-case query of "*" for better performance. */
- if (strcmp (notmuch_query_get_query_string (query), "*") == 0) {
- tags = notmuch_database_get_all_tags (notmuch);
- } else {
- notmuch_status_t status;
- status = notmuch_query_search_messages_st (query, &messages);
- if (print_status_query ("notmuch search", query, status))
- return 1;
- tags = notmuch_messages_collect_tags (messages);
- }
- if (tags == NULL)
+ if (print_status_query ("notmuch search",
+ query,
+ notmuch_query_search_tags (query, &tags)))
return 1;
format->begin_list (format);
@@ -653,9 +640,6 @@ do_search_tags (const search_context_t *ctx)
notmuch_tags_destroy (tags);
- if (messages)
- notmuch_messages_destroy (messages);
-
format->end (format);
return 0;
--
2.8.1
next prev parent reply other threads:[~2016-06-30 8:40 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-04 12:45 [Jameson Graef Rollins] Bug#826280: notmuch: shortcut to list tags David Bremner
2016-06-04 12:53 ` David Bremner
[not found] ` <CAMEnOBLrmjhERgGRJ2UC8ZSPQOEPCtr7_4pqq+Uot201G2fDcA@mail.gmail.com>
2016-06-04 17:52 ` David Bremner
2016-06-05 9:51 ` Tomi Ollila
2016-06-30 8:40 ` RFC: do what jamie wants with notmuch tag David Bremner
2016-06-30 8:40 ` David Bremner [this message]
2016-06-30 8:40 ` [PATCH 2/2] WIP: treat notmuch tag without operations as query 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=1467276027-30633-2-git-send-email-david@tethera.net \
--to=david@tethera.net \
--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).