aboutsummaryrefslogtreecommitdiff
path: root/lib/query.cc
diff options
context:
space:
mode:
authorDavid Bremner <david@tethera.net>2015-09-27 12:31:57 -0300
committerDavid Bremner <david@tethera.net>2015-10-05 19:44:07 -0300
commit87ee9a53e36f395e73e16da12cb268a708147259 (patch)
treec73d4e86d385edd8337cf047c0d3707f01cc0c02 /lib/query.cc
parent81bd41c7cb59a8d70932e6bdbee6e1e2cde5477f (diff)
lib: add versions of n_q_count_{message,threads} with status return
Although I think it's a pretty bad idea to continue using the old API, this allows both a more gentle transition for clients of the library, and allows us to break one monolithic change into a series
Diffstat (limited to 'lib/query.cc')
-rw-r--r--lib/query.cc47
1 files changed, 33 insertions, 14 deletions
diff --git a/lib/query.cc b/lib/query.cc
index 8cf0a077..e627bfc2 100644
--- a/lib/query.cc
+++ b/lib/query.cc
@@ -541,9 +541,19 @@ notmuch_threads_destroy (notmuch_threads_t *threads)
talloc_free (threads);
}
-unsigned
+unsigned int
notmuch_query_count_messages (notmuch_query_t *query)
{
+ notmuch_status_t status;
+ unsigned int count;
+
+ status = notmuch_query_count_messages_st (query, &count);
+ return status ? 0 : count;
+}
+
+notmuch_status_t
+notmuch_query_count_messages_st (notmuch_query_t *query, unsigned *count_out)
+{
notmuch_database_t *notmuch = query->notmuch;
const char *query_string = query->query_string;
Xapian::doccount count = 0;
@@ -605,35 +615,44 @@ notmuch_query_count_messages (notmuch_query_t *query)
"Query string was: %s\n",
error.get_msg().c_str(),
query->query_string);
-
+ return NOTMUCH_STATUS_XAPIAN_EXCEPTION;
}
- return count;
+ *count_out = count;
+ return NOTMUCH_STATUS_SUCCESS;
}
unsigned
notmuch_query_count_threads (notmuch_query_t *query)
{
+ notmuch_status_t status;
+ unsigned int count;
+
+ status = notmuch_query_count_threads_st (query, &count);
+ return status ? 0 : count;
+}
+
+notmuch_status_t
+notmuch_query_count_threads_st (notmuch_query_t *query, unsigned *count)
+{
notmuch_messages_t *messages;
GHashTable *hash;
- unsigned int count;
notmuch_sort_t sort;
- notmuch_status_t status;
+ notmuch_status_t ret = NOTMUCH_STATUS_SUCCESS;
sort = query->sort;
query->sort = NOTMUCH_SORT_UNSORTED;
- status = notmuch_query_search_messages_st (query, &messages);
- if (status)
- return 0;
-
+ ret = notmuch_query_search_messages_st (query, &messages);
+ if (ret)
+ return ret;
query->sort = sort;
if (messages == NULL)
- return 0;
+ return NOTMUCH_STATUS_XAPIAN_EXCEPTION;
hash = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, NULL);
if (hash == NULL) {
talloc_free (messages);
- return 0;
+ return NOTMUCH_STATUS_OUT_OF_MEMORY;
}
while (notmuch_messages_valid (messages)) {
@@ -642,7 +661,7 @@ notmuch_query_count_threads (notmuch_query_t *query)
char *thread_id_copy = talloc_strdup (messages, thread_id);
if (unlikely (thread_id_copy == NULL)) {
notmuch_message_destroy (message);
- count = 0;
+ ret = NOTMUCH_STATUS_OUT_OF_MEMORY;
goto DONE;
}
g_hash_table_insert (hash, thread_id_copy, NULL);
@@ -650,13 +669,13 @@ notmuch_query_count_threads (notmuch_query_t *query)
notmuch_messages_move_to_next (messages);
}
- count = g_hash_table_size (hash);
+ *count = g_hash_table_size (hash);
DONE:
g_hash_table_unref (hash);
talloc_free (messages);
- return count;
+ return ret;
}
notmuch_database_t *