unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* updated count / search API patches
@ 2015-03-07 19:22 David Bremner
  2015-03-07 19:22 ` [PATCH 1/5] lib: define NOTMUCH_DEPRECATED macro, document its use David Bremner
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: David Bremner @ 2015-03-07 19:22 UTC (permalink / raw)
  To: notmuch

This draws together patches from a few different threads, deferring
the bindings patches until later. Most of these have been reviewed by
Jani, with the notable exception of 3/5.

There are fair number of small changes in 3/5. They are mostly pretty
straight forward, but it wouldn't hurt to have a second pair of eyes
on them.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/5] lib: define NOTMUCH_DEPRECATED macro, document its use.
  2015-03-07 19:22 updated count / search API patches David Bremner
@ 2015-03-07 19:22 ` David Bremner
  2015-03-07 19:22 ` [PATCH 2/5] lib: deprecate notmuch_query_search_{threads, messages} David Bremner
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: David Bremner @ 2015-03-07 19:22 UTC (permalink / raw)
  To: notmuch

This has been tested with gcc and clang.
---
 devel/STYLE     | 10 ++++++++++
 doc/doxygen.cfg |  2 +-
 lib/notmuch.h   |  2 ++
 3 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/devel/STYLE b/devel/STYLE
index 92de42c..24bd548 100644
--- a/devel/STYLE
+++ b/devel/STYLE
@@ -93,3 +93,13 @@ libnotmuch conventions
 
 * Code which needs to be accessed from both the CLI and from
   libnotmuch should be factored out into libutil (under util/).
+
+* Deprecated functions should be marked with the NOTMUCH_DEPRECATED
+  macro which generates run time warnings with gcc and clang. In order
+  not to confuse doxygen this should go at the beginning of the
+  declaration like:
+
+  NOTMUCH_DEPRECATED(major,minor) notmuch_status_t notmuch_dwim(void *arg);
+
+  The @deprecated doxygen command can be used to generate markup in
+  the API docs.
diff --git a/doc/doxygen.cfg b/doc/doxygen.cfg
index 42b6339..c033f34 100644
--- a/doc/doxygen.cfg
+++ b/doc/doxygen.cfg
@@ -74,7 +74,7 @@ STRICT_PROTO_MATCHING  = NO
 GENERATE_TODOLIST      = NO
 GENERATE_TESTLIST      = NO
 GENERATE_BUGLIST       = NO
-GENERATE_DEPRECATEDLIST= NO
+GENERATE_DEPRECATEDLIST= YES
 ENABLED_SECTIONS       =
 MAX_INITIALIZER_LINES  = 30
 SHOW_USED_FILES        = NO
diff --git a/lib/notmuch.h b/lib/notmuch.h
index f0b60b8..5352479 100644
--- a/lib/notmuch.h
+++ b/lib/notmuch.h
@@ -59,6 +59,8 @@ NOTMUCH_BEGIN_DECLS
 #define LIBNOTMUCH_MINOR_VERSION	2
 #define LIBNOTMUCH_MICRO_VERSION	0
 
+#define NOTMUCH_DEPRECATED(major,minor) \
+    __attribute__ ((deprecated ("function deprecated as of libnotmuch " #major "." #minor)))
 #endif /* __DOXYGEN__ */
 
 /**
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/5] lib: deprecate notmuch_query_search_{threads, messages}
  2015-03-07 19:22 updated count / search API patches David Bremner
  2015-03-07 19:22 ` [PATCH 1/5] lib: define NOTMUCH_DEPRECATED macro, document its use David Bremner
@ 2015-03-07 19:22 ` David Bremner
  2015-03-07 19:23 ` [PATCH 3/5] cli/lib: remove most use of deprecated notmuch_query_search_{messages,threads} David Bremner
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: David Bremner @ 2015-03-07 19:22 UTC (permalink / raw)
  To: notmuch

The CLI (and bindings) code should really be updated to use the new
status-code-returning versions. Here are some warnings to prod us (and
other clients) to do so.
---
 lib/notmuch.h | 41 ++++++++++++++++++++++++++---------------
 1 file changed, 26 insertions(+), 15 deletions(-)

diff --git a/lib/notmuch.h b/lib/notmuch.h
index 5352479..087f3f0 100644
--- a/lib/notmuch.h
+++ b/lib/notmuch.h
@@ -781,20 +781,25 @@ notmuch_query_add_tag_exclude (notmuch_query_t *query, const char *tag);
  * notmuch_threads_destroy function, but there's no good reason
  * to call it if the query is about to be destroyed).
  *
- * If a Xapian exception occurs this function will return NULL.
- * For better error reporting, use the _st variant.
- */
-notmuch_threads_t *
-notmuch_query_search_threads (notmuch_query_t *query);
-
-/**
- * Like notmuch_query_search_threads, but with a status return.
  */
 notmuch_status_t
 notmuch_query_search_threads_st (notmuch_query_t *query,
 				 notmuch_threads_t **out);
 
 /**
+ * Like notmuch_query_search_threads_st, but without a status return.
+ *
+ * If a Xapian exception occurs this function will return NULL.
+ *
+ * @deprecated Deprecated as of libnotmuch 4.2 (notmuch 0.20). Please
+ * use notmuch_query_search_threads_st instead.
+ *
+ */
+NOTMUCH_DEPRECATED(4,2)
+notmuch_threads_t *
+notmuch_query_search_threads (notmuch_query_t *query);
+
+/**
  * Execute a query for messages, returning a notmuch_messages_t object
  * which can be used to iterate over the results. The returned
  * messages object is owned by the query and as such, will only be
@@ -832,17 +837,23 @@ notmuch_query_search_threads_st (notmuch_query_t *query,
  * reason to call it if the query is about to be destroyed).
  *
  * If a Xapian exception occurs this function will return NULL.
- * For better error reporting, use the _st variant.
- */
-notmuch_messages_t *
-notmuch_query_search_messages (notmuch_query_t *query);
-
-/**
- * Like notmuch_query_search_messages, but with a status return.
+ *
  */
 notmuch_status_t
 notmuch_query_search_messages_st (notmuch_query_t *query,
 				  notmuch_messages_t **out);
+/**
+ * Like notmuch_query_search_messages, but without a status return.
+ *
+ * If a Xapian exception occurs this function will return NULL.
+ *
+ * @deprecated Deprecated as of libnotmuch 4.2 (notmuch 0.20). Please use
+ * notmuch_query_search_messages_st instead.
+ *
+ */
+NOTMUCH_DEPRECATED(4,2)
+notmuch_messages_t *
+notmuch_query_search_messages (notmuch_query_t *query);
 
 /**
  * Destroy a notmuch_query_t along with any associated resources.
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 3/5] cli/lib: remove most use of deprecated notmuch_query_search_{messages,threads}
  2015-03-07 19:22 updated count / search API patches David Bremner
  2015-03-07 19:22 ` [PATCH 1/5] lib: define NOTMUCH_DEPRECATED macro, document its use David Bremner
  2015-03-07 19:22 ` [PATCH 2/5] lib: deprecate notmuch_query_search_{threads, messages} David Bremner
@ 2015-03-07 19:23 ` David Bremner
  2015-03-07 19:23 ` [PATCH 4/5] lib: add versions of notmuch_query_count_{message,threads} with status return David Bremner
  2015-03-07 19:23 ` [PATCH 5/5] cli: update to use new count API David Bremner
  4 siblings, 0 replies; 6+ messages in thread
From: David Bremner @ 2015-03-07 19:23 UTC (permalink / raw)
  To: notmuch

There two remaining cases in the lib that seem to require more than a
simple replacement of the old call, with the new call plus a check of
the return value.
---
 lib/database.cc  |  2 ++
 lib/query.cc     |  4 +++-
 lib/thread.cc    |  2 ++
 notmuch-count.c  |  5 +++--
 notmuch-dump.c   |  7 ++++++-
 notmuch-reply.c  | 25 ++++++++++++++++++++++---
 notmuch-search.c | 21 +++++++++++++++------
 notmuch-show.c   | 13 ++++++++++---
 notmuch-tag.c    |  8 +++++++-
 9 files changed, 70 insertions(+), 17 deletions(-)

diff --git a/lib/database.cc b/lib/database.cc
index 3974e2e..8680963 100644
--- a/lib/database.cc
+++ b/lib/database.cc
@@ -1306,6 +1306,8 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,
 	notmuch_message_t *message;
 	char *filename;
 
+	/* XXX: this should use the _st version, but needs an error
+	   path */
 	for (messages = notmuch_query_search_messages (query);
 	     notmuch_messages_valid (messages);
 	     notmuch_messages_move_to_next (messages))
diff --git a/lib/query.cc b/lib/query.cc
index 9279915..1871a81 100644
--- a/lib/query.cc
+++ b/lib/query.cc
@@ -610,7 +610,9 @@ notmuch_query_count_threads (notmuch_query_t *query)
 
     sort = query->sort;
     query->sort = NOTMUCH_SORT_UNSORTED;
-    messages = notmuch_query_search_messages (query);
+    ret = notmuch_query_search_messages_st (query, &messages);
+    if (ret)
+	return ret;
     query->sort = sort;
     if (messages == NULL)
 	return 0;
diff --git a/lib/thread.cc b/lib/thread.cc
index 9847cf8..c8e58c3 100644
--- a/lib/thread.cc
+++ b/lib/thread.cc
@@ -504,6 +504,8 @@ _notmuch_thread_create (void *ctx,
      * oldest or newest subject is desired. */
     notmuch_query_set_sort (thread_id_query, NOTMUCH_SORT_OLDEST_FIRST);
 
+    /* XXX: this should use the _st version, but it needs an error path
+     */
     for (messages = notmuch_query_search_messages (thread_id_query);
 	 notmuch_messages_valid (messages);
 	 notmuch_messages_move_to_next (messages))
diff --git a/notmuch-count.c b/notmuch-count.c
index 6058f7c..d555bf1 100644
--- a/notmuch-count.c
+++ b/notmuch-count.c
@@ -39,10 +39,11 @@ count_files (notmuch_query_t *query)
     notmuch_messages_t *messages;
     notmuch_message_t *message;
     notmuch_filenames_t *filenames;
+    notmuch_status_t status;
     unsigned int count = 0;
 
-    messages = notmuch_query_search_messages (query);
-    if (messages == NULL)
+    status = notmuch_query_search_messages_st (query, &messages);
+    if (status)
 	return 0;
 
     for (;
diff --git a/notmuch-dump.c b/notmuch-dump.c
index 9c6ad7f..c6154a9 100644
--- a/notmuch-dump.c
+++ b/notmuch-dump.c
@@ -48,8 +48,13 @@ database_dump_file (notmuch_database_t *notmuch, gzFile output,
 
     char *buffer = NULL;
     size_t buffer_size = 0;
+    notmuch_status_t status;
 
-    for (messages = notmuch_query_search_messages (query);
+    status = notmuch_query_search_messages_st (query, &messages);
+    if (status)
+	return EXIT_FAILURE;
+    
+    for (;
 	 notmuch_messages_valid (messages);
 	 notmuch_messages_move_to_next (messages)) {
 	int first = 1;
diff --git a/notmuch-reply.c b/notmuch-reply.c
index 7c1c809..dca4e42 100644
--- a/notmuch-reply.c
+++ b/notmuch-reply.c
@@ -606,8 +606,15 @@ notmuch_reply_format_default(void *ctx,
     notmuch_messages_t *messages;
     notmuch_message_t *message;
     mime_node_t *root;
+    notmuch_status_t status;
 
-    for (messages = notmuch_query_search_messages (query);
+    status = notmuch_query_search_messages_st (query, &messages);
+    if (status) {
+	fprintf (stderr, "Error: %s.\n", notmuch_status_to_string (status));
+	return 1;
+    }
+    
+    for (;
 	 notmuch_messages_valid (messages);
 	 notmuch_messages_move_to_next (messages))
     {
@@ -656,7 +663,12 @@ notmuch_reply_format_sprinter(void *ctx,
 	return 1;
     }
 
-    messages = notmuch_query_search_messages (query);
+    status = notmuch_query_search_messages_st (query, &messages);
+    if (status) {
+	fprintf (stderr, "Error: %s.\n", notmuch_status_to_string (status));
+	return 1;
+    }
+
     message = notmuch_messages_get (messages);
     if (mime_node_open (ctx, message, &(params->crypto), &node) != NOTMUCH_STATUS_SUCCESS)
 	return 1;
@@ -698,8 +710,15 @@ notmuch_reply_format_headers_only(void *ctx,
     notmuch_message_t *message;
     const char *in_reply_to, *orig_references, *references;
     char *reply_headers;
+    notmuch_status_t status;
 
-    for (messages = notmuch_query_search_messages (query);
+    status = notmuch_query_search_messages_st (query, &messages);    
+    if (status) {
+	fprintf (stderr, "Error: %s.\n", notmuch_status_to_string (status));
+	return 1;
+    }
+    
+    for (;
 	 notmuch_messages_valid (messages);
 	 notmuch_messages_move_to_next (messages))
     {
diff --git a/notmuch-search.c b/notmuch-search.c
index a591d45..20feda4 100644
--- a/notmuch-search.c
+++ b/notmuch-search.c
@@ -111,6 +111,7 @@ do_search_threads (search_context_t *ctx)
     sprinter_t *format = ctx->format;
     time_t date;
     int i;
+    notmuch_status_t status;
 
     if (ctx->offset < 0) {
 	ctx->offset += notmuch_query_count_threads (ctx->query);
@@ -118,9 +119,11 @@ do_search_threads (search_context_t *ctx)
 	    ctx->offset = 0;
     }
 
-    threads = notmuch_query_search_threads (ctx->query);
-    if (threads == NULL)
+    status = notmuch_query_search_threads_st (ctx->query, &threads);
+    if (status) {
+	fprintf (stderr, "Error: %s.\n", notmuch_status_to_string (status));
 	return 1;
+    }
 
     format->begin_list (format);
 
@@ -412,6 +415,7 @@ do_search_messages (search_context_t *ctx)
     notmuch_filenames_t *filenames;
     sprinter_t *format = ctx->format;
     int i;
+    notmuch_status_t status;
 
     if (ctx->offset < 0) {
 	ctx->offset += notmuch_query_count_messages (ctx->query);
@@ -419,9 +423,11 @@ do_search_messages (search_context_t *ctx)
 	    ctx->offset = 0;
     }
 
-    messages = notmuch_query_search_messages (ctx->query);
-    if (messages == NULL)
+    status = notmuch_query_search_messages_st (ctx->query, &messages);
+    if (status) {
+	fprintf (stderr, "Error: %s.\n", notmuch_status_to_string (status));
 	return 1;
+    }
 
     format->begin_list (format);
 
@@ -508,9 +514,12 @@ do_search_tags (const search_context_t *ctx)
     if (strcmp (notmuch_query_get_query_string (query), "*") == 0) {
 	tags = notmuch_database_get_all_tags (notmuch);
     } else {
-	messages = notmuch_query_search_messages (query);
-	if (messages == NULL)
+	notmuch_status_t status;
+	status = notmuch_query_search_messages_st (query, &messages);
+	if (status) {
+	    fprintf (stderr, "Error: %s.\n", notmuch_status_to_string (status));
 	    return 1;
+	}
 
 	tags = notmuch_messages_collect_tags (messages);
     }
diff --git a/notmuch-show.c b/notmuch-show.c
index d416fbd..af8741d 100644
--- a/notmuch-show.c
+++ b/notmuch-show.c
@@ -988,7 +988,12 @@ do_show_single (void *ctx,
 	return 1;
     }
 
-    messages = notmuch_query_search_messages (query);
+    status = notmuch_query_search_messages_st (query, &messages);
+    if (status) {
+	fprintf (stderr, "Error: %s.\n", notmuch_status_to_string (status));
+	return 1;
+    }
+    
     message = notmuch_messages_get (messages);
 
     if (message == NULL) {
@@ -1015,9 +1020,11 @@ do_show (void *ctx,
     notmuch_messages_t *messages;
     notmuch_status_t status, res = NOTMUCH_STATUS_SUCCESS;
 
-    threads = notmuch_query_search_threads (query);
-    if (! threads)
+    status= notmuch_query_search_threads_st (query, &threads);
+    if (status) {
+	fprintf (stderr, "Error: %s.\n", notmuch_status_to_string (status));
 	return 1;
+    }
 
     sp->begin_list (sp);
 
diff --git a/notmuch-tag.c b/notmuch-tag.c
index 5b2f1e4..dcaca43 100644
--- a/notmuch-tag.c
+++ b/notmuch-tag.c
@@ -97,6 +97,8 @@ tag_query (void *ctx, notmuch_database_t *notmuch, const char *query_string,
     notmuch_query_t *query;
     notmuch_messages_t *messages;
     notmuch_message_t *message;
+    notmuch_status_t status;
+    
     int ret = NOTMUCH_STATUS_SUCCESS;
 
     if (! (flags & TAG_FLAG_REMOVE_ALL)) {
@@ -119,7 +121,11 @@ tag_query (void *ctx, notmuch_database_t *notmuch, const char *query_string,
     /* tagging is not interested in any special sort order */
     notmuch_query_set_sort (query, NOTMUCH_SORT_UNSORTED);
 
-    for (messages = notmuch_query_search_messages (query);
+    status = notmuch_query_search_messages_st (query, &messages);
+    if (status)
+	return status;
+    
+    for (; 
 	 notmuch_messages_valid (messages) && ! interrupted;
 	 notmuch_messages_move_to_next (messages)) {
 	message = notmuch_messages_get (messages);
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 4/5] lib: add versions of notmuch_query_count_{message,threads} with status return
  2015-03-07 19:22 updated count / search API patches David Bremner
                   ` (2 preceding siblings ...)
  2015-03-07 19:23 ` [PATCH 3/5] cli/lib: remove most use of deprecated notmuch_query_search_{messages,threads} David Bremner
@ 2015-03-07 19:23 ` David Bremner
  2015-03-07 19:23 ` [PATCH 5/5] cli: update to use new count API David Bremner
  4 siblings, 0 replies; 6+ messages in thread
From: David Bremner @ 2015-03-07 19:23 UTC (permalink / raw)
  To: notmuch

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
---
 lib/database.cc |  8 +++++++-
 lib/notmuch.h   | 52 ++++++++++++++++++++++++++++++++++++++++++++++------
 lib/query.cc    | 38 ++++++++++++++++++++++++++++++--------
 3 files changed, 83 insertions(+), 15 deletions(-)

diff --git a/lib/database.cc b/lib/database.cc
index 8680963..b8fb7f7 100644
--- a/lib/database.cc
+++ b/lib/database.cc
@@ -1275,7 +1275,13 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,
     if (new_features &
 	(NOTMUCH_FEATURE_FILE_TERMS | NOTMUCH_FEATURE_BOOL_FOLDER)) {
 	notmuch_query_t *query = notmuch_query_create (notmuch, "");
-	total += notmuch_query_count_messages (query);
+	unsigned msg_count;
+
+	status = notmuch_query_count_messages_st (query, &msg_count);
+	if (status)
+	    goto DONE;
+
+	total += msg_count;
 	notmuch_query_destroy (query);
     }
     if (new_features & NOTMUCH_FEATURE_DIRECTORY_DOCS) {
diff --git a/lib/notmuch.h b/lib/notmuch.h
index 087f3f0..2acfbb5 100644
--- a/lib/notmuch.h
+++ b/lib/notmuch.h
@@ -927,12 +927,31 @@ notmuch_threads_destroy (notmuch_threads_t *threads);
  * This function performs a search and returns Xapian's best
  * guess as to number of matching messages.
  *
- * If a Xapian exception occurs, this function may return 0 (after
- * printing a message).
+ * @returns
+ *
+ * NOTMUCH_STATUS_SUCCESS: query complete successfully.
+ *
+ * NOTMUCH_STATUS_XAPIAN_EXCEPTION: a Xapian exception occured. The
+ *      value of *count is not defined.
  */
-unsigned
+notmuch_status_t
+notmuch_query_count_messages_st (notmuch_query_t *query, unsigned *count);
+
+/**
+ * like notmuch_query_count_messages_st, but without a status return
+ *
+ * May return 0 in the case of errors.
+ *
+ * @deprecated Deprecated since libnotmuch 4.2 (notmuch 0.20). Please
+ * use notmuch_query_count_messages_st instead.
+ */
+NOTMUCH_DEPRECATED(4,2)
+unsigned int
 notmuch_query_count_messages (notmuch_query_t *query);
 
+
+
+
 /**
  * Return the number of threads matching a search.
  *
@@ -941,13 +960,34 @@ notmuch_query_count_messages (notmuch_query_t *query);
  * search.
  *
  * Note that this is a significantly heavier operation than
- * notmuch_query_count_messages().
+ * notmuch_query_count_messages{_st}().
  *
- * If an error occurs, this function may return 0.
+ * @returns
+ *
+ * NOTMUCH_STATUS_OUT_OF_MEMORY: Memory allocation failed. The value
+ *      of *count is not defined
+
+ * NOTMUCH_STATUS_SUCCESS: query complete successfully.
+ *
+ * NOTMUCH_STATUS_XAPIAN_EXCEPTION: a Xapian exception occured. The
+ *      value of *count is not defined.
  */
-unsigned
+notmuch_status_t
+notmuch_query_count_threads_st (notmuch_query_t *query, unsigned *count);
+
+/**
+ * like notmuch_query_count_threads, but without a status return.
+ *
+ * May return 0 in case of errors.
+ *
+ * @deprecated Deprecated as of libnotmuch 4.2 (notmuch 0.20). Please
+ * use notmuch_query_count_threads_st instead.
+ */
+NOTMUCH_DEPRECATED(4,2)
+unsigned int
 notmuch_query_count_threads (notmuch_query_t *query);
 
+
 /**
  * Get the thread ID of 'thread'.
  *
diff --git a/lib/query.cc b/lib/query.cc
index 1871a81..984f577 100644
--- a/lib/query.cc
+++ b/lib/query.cc
@@ -538,9 +538,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;
@@ -595,18 +605,30 @@ notmuch_query_count_messages (notmuch_query_t *query)
 	fprintf (stderr, "A Xapian exception occurred: %s\n",
 		 error.get_msg().c_str());
 	fprintf (stderr, "Query string was: %s\n", 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 ret = NOTMUCH_STATUS_SUCCESS;
 
     sort = query->sort;
     query->sort = NOTMUCH_SORT_UNSORTED;
@@ -615,12 +637,12 @@ notmuch_query_count_threads (notmuch_query_t *query)
 	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)) {
@@ -629,7 +651,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);
@@ -637,11 +659,11 @@ 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;
 }
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 5/5] cli: update to use new count API
  2015-03-07 19:22 updated count / search API patches David Bremner
                   ` (3 preceding siblings ...)
  2015-03-07 19:23 ` [PATCH 4/5] lib: add versions of notmuch_query_count_{message,threads} with status return David Bremner
@ 2015-03-07 19:23 ` David Bremner
  4 siblings, 0 replies; 6+ messages in thread
From: David Bremner @ 2015-03-07 19:23 UTC (permalink / raw)
  To: notmuch

Essentially replace each call to notmuch_count_* with an if block.
---
 notmuch-count.c  | 16 ++++++++++++++--
 notmuch-reply.c  | 11 ++++++++++-
 notmuch-search.c | 17 +++++++++++++++--
 notmuch-show.c   | 11 ++++++++++-
 4 files changed, 49 insertions(+), 6 deletions(-)

diff --git a/notmuch-count.c b/notmuch-count.c
index d555bf1..b475495 100644
--- a/notmuch-count.c
+++ b/notmuch-count.c
@@ -72,6 +72,8 @@ print_count (notmuch_database_t *notmuch, const char *query_str,
 {
     notmuch_query_t *query;
     size_t i;
+    unsigned count;
+    notmuch_status_t status;
 
     query = notmuch_query_create (notmuch, query_str);
     if (query == NULL) {
@@ -84,10 +86,20 @@ print_count (notmuch_database_t *notmuch, const char *query_str,
 
     switch (output) {
     case OUTPUT_MESSAGES:
-	printf ("%u\n", notmuch_query_count_messages (query));
+	status = notmuch_query_count_messages_st (query, &count);
+	if (status) {
+	    fprintf (stderr, "Error: %s\n", notmuch_status_to_string (status));
+	    return 1;
+	}
+	printf ("%u\n", count);
 	break;
     case OUTPUT_THREADS:
-	printf ("%u\n", notmuch_query_count_threads (query));
+	status = notmuch_query_count_threads_st (query, &count);
+	if (status) {
+	    fprintf (stderr, "Error: %s\n", notmuch_status_to_string (status));
+	    return 1;
+	}
+	printf ("%u\n", count);
 	break;
     case OUTPUT_FILES:
 	printf ("%u\n", count_files (query));
diff --git a/notmuch-reply.c b/notmuch-reply.c
index dca4e42..88998c3 100644
--- a/notmuch-reply.c
+++ b/notmuch-reply.c
@@ -657,8 +657,17 @@ notmuch_reply_format_sprinter(void *ctx,
     notmuch_messages_t *messages;
     notmuch_message_t *message;
     mime_node_t *node;
+    unsigned count;
+    notmuch_status_t status;
+
+    status = notmuch_query_count_messages_st (query, &count);
+
+    if (status) {
+	fprintf (stderr, "Error: %s.\n", notmuch_status_to_string (status));
+	return 1;
+    }
 
-    if (notmuch_query_count_messages (query) != 1) {
+    if (count != 1) {
 	fprintf (stderr, "Error: search term did not match precisely one message.\n");
 	return 1;
     }
diff --git a/notmuch-search.c b/notmuch-search.c
index 20feda4..d8020f2 100644
--- a/notmuch-search.c
+++ b/notmuch-search.c
@@ -114,7 +114,15 @@ do_search_threads (search_context_t *ctx)
     notmuch_status_t status;
 
     if (ctx->offset < 0) {
-	ctx->offset += notmuch_query_count_threads (ctx->query);
+	unsigned count;
+	notmuch_status_t status;
+	status = notmuch_query_count_threads_st (ctx->query, &count);
+	if (status) {
+	    fprintf (stderr, "Error: %s\n", notmuch_status_to_string (status));
+	    return 1;
+	}
+
+	ctx->offset += count;
 	if (ctx->offset < 0)
 	    ctx->offset = 0;
     }
@@ -418,7 +426,12 @@ do_search_messages (search_context_t *ctx)
     notmuch_status_t status;
 
     if (ctx->offset < 0) {
-	ctx->offset += notmuch_query_count_messages (ctx->query);
+	unsigned count;
+	notmuch_status_t status;
+	status = notmuch_query_count_messages_st (ctx->query, &count);
+	if (status)
+	    return 1;
+	ctx->offset += count;
 	if (ctx->offset < 0)
 	    ctx->offset = 0;
     }
diff --git a/notmuch-show.c b/notmuch-show.c
index af8741d..834ed89 100644
--- a/notmuch-show.c
+++ b/notmuch-show.c
@@ -982,8 +982,17 @@ do_show_single (void *ctx,
 {
     notmuch_messages_t *messages;
     notmuch_message_t *message;
+    unsigned count;
+    notmuch_status_t status;
+
+    status = notmuch_query_count_messages_st (query, &count);
+
+    if (status) {
+	fprintf (stderr, "Error: %s\n", notmuch_status_to_string (status));
+	return 1;
+    }
 
-    if (notmuch_query_count_messages (query) != 1) {
+    if (count != 1) {
 	fprintf (stderr, "Error: search term did not match precisely one message.\n");
 	return 1;
     }
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2015-03-07 19:25 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-03-07 19:22 updated count / search API patches David Bremner
2015-03-07 19:22 ` [PATCH 1/5] lib: define NOTMUCH_DEPRECATED macro, document its use David Bremner
2015-03-07 19:22 ` [PATCH 2/5] lib: deprecate notmuch_query_search_{threads, messages} David Bremner
2015-03-07 19:23 ` [PATCH 3/5] cli/lib: remove most use of deprecated notmuch_query_search_{messages,threads} David Bremner
2015-03-07 19:23 ` [PATCH 4/5] lib: add versions of notmuch_query_count_{message,threads} with status return David Bremner
2015-03-07 19:23 ` [PATCH 5/5] cli: update to use new count API David Bremner

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).