unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* update cli/lib to use new notmuch_query_search_* api
@ 2015-06-07 15:01 David Bremner
  2015-06-07 15:01 ` [PATCH 01/10] lib: define NOTMUCH_DEPRECATED macro, document its use David Bremner
                   ` (10 more replies)
  0 siblings, 11 replies; 13+ messages in thread
From: David Bremner @ 2015-06-07 15:01 UTC (permalink / raw)
  To: notmuch

I was already to push the first few patches of

  id:1425756182-28468-1-git-send-email-david@tethera.net

When I realized there was probably a reason that no-one had reviewed
patch 3/5. After breaking up that ball of mud, one thing led to
another, and deprecating the old API and updating to the new API is up
to 10 patches.

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

* [PATCH 01/10] lib: define NOTMUCH_DEPRECATED macro, document its use.
  2015-06-07 15:01 update cli/lib to use new notmuch_query_search_* api David Bremner
@ 2015-06-07 15:01 ` David Bremner
  2015-06-07 15:01 ` [PATCH 02/10] lib: deprecate notmuch_query_search_{threads, messages} David Bremner
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 13+ messages in thread
From: David Bremner @ 2015-06-07 15:01 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 20c4e01..6a69f31 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] 13+ messages in thread

* [PATCH 02/10] lib: deprecate notmuch_query_search_{threads, messages}
  2015-06-07 15:01 update cli/lib to use new notmuch_query_search_* api David Bremner
  2015-06-07 15:01 ` [PATCH 01/10] lib: define NOTMUCH_DEPRECATED macro, document its use David Bremner
@ 2015-06-07 15:01 ` David Bremner
  2015-06-07 15:01 ` [PATCH 03/10] lib: add public accessor for database from query David Bremner
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 13+ messages in thread
From: David Bremner @ 2015-06-07 15:01 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 6a69f31..c2ada4b 100644
--- a/lib/notmuch.h
+++ b/lib/notmuch.h
@@ -809,20 +809,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.3 (notmuch 0.21). Please
+ * use notmuch_query_search_threads_st instead.
+ *
+ */
+NOTMUCH_DEPRECATED(4,3)
+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
@@ -860,17 +865,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.3 (notmuch 0.21). Please use
+ * notmuch_query_search_messages_st instead.
+ *
+ */
+NOTMUCH_DEPRECATED(4,3)
+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] 13+ messages in thread

* [PATCH 03/10] lib: add public accessor for database from query
  2015-06-07 15:01 update cli/lib to use new notmuch_query_search_* api David Bremner
  2015-06-07 15:01 ` [PATCH 01/10] lib: define NOTMUCH_DEPRECATED macro, document its use David Bremner
  2015-06-07 15:01 ` [PATCH 02/10] lib: deprecate notmuch_query_search_{threads, messages} David Bremner
@ 2015-06-07 15:01 ` David Bremner
  2015-06-07 15:01 ` [PATCH 04/10] lib: remove use of notmuch_query_search_messages from query.cc David Bremner
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 13+ messages in thread
From: David Bremner @ 2015-06-07 15:01 UTC (permalink / raw)
  To: notmuch

This is to make it easier for clients of the library to update to the
new error code returning versions of notmuch_query_search_messages
---
 lib/Makefile.local | 2 +-
 lib/notmuch.h      | 6 ++++++
 lib/query.cc       | 6 ++++++
 3 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/lib/Makefile.local b/lib/Makefile.local
index f9ecd50..aa76b61 100644
--- a/lib/Makefile.local
+++ b/lib/Makefile.local
@@ -11,7 +11,7 @@ LIBNOTMUCH_VERSION_MAJOR = 4
 # the time of release for any additions to the library interface,
 # (and when it is incremented, the release version of the library should
 #  be reset to 0).
-LIBNOTMUCH_VERSION_MINOR = 2
+LIBNOTMUCH_VERSION_MINOR = 3
 
 # The release version the library interface. This should be incremented at
 # the time of release if there have been no changes to the interface, (but
diff --git a/lib/notmuch.h b/lib/notmuch.h
index c2ada4b..46115c8 100644
--- a/lib/notmuch.h
+++ b/lib/notmuch.h
@@ -708,6 +708,12 @@ const char *
 notmuch_query_get_query_string (notmuch_query_t *query);
 
 /**
+ * Return the notmuch database of this query. See notmuch_query_create.
+ */
+notmuch_database_t *
+notmuch_query_get_database (notmuch_query_t *query);
+
+/**
  * Exclude values for notmuch_query_set_omit_excluded. The strange
  * order is to maintain backward compatibility: the old FALSE/TRUE
  * options correspond to the new
diff --git a/lib/query.cc b/lib/query.cc
index 9cedb6a..5275b5a 100644
--- a/lib/query.cc
+++ b/lib/query.cc
@@ -654,3 +654,9 @@ notmuch_query_count_threads (notmuch_query_t *query)
 
     return count;
 }
+
+notmuch_database_t *
+notmuch_query_get_database (notmuch_query_t *query)
+{
+    return query->notmuch;
+}
-- 
2.1.4

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

* [PATCH 04/10] lib: remove use of notmuch_query_search_messages from query.cc
  2015-06-07 15:01 update cli/lib to use new notmuch_query_search_* api David Bremner
                   ` (2 preceding siblings ...)
  2015-06-07 15:01 ` [PATCH 03/10] lib: add public accessor for database from query David Bremner
@ 2015-06-07 15:01 ` David Bremner
  2015-06-07 15:01 ` [PATCH 05/10] lib: note remaining uses of deprecated message search API David Bremner
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 13+ messages in thread
From: David Bremner @ 2015-06-07 15:01 UTC (permalink / raw)
  To: notmuch

There is not too much point in worrying about the bad error reporting
here, because the count api is due for the same deprecation.
---
 lib/query.cc | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/lib/query.cc b/lib/query.cc
index 5275b5a..f53215d 100644
--- a/lib/query.cc
+++ b/lib/query.cc
@@ -618,10 +618,14 @@ notmuch_query_count_threads (notmuch_query_t *query)
     GHashTable *hash;
     unsigned int count;
     notmuch_sort_t sort;
+    notmuch_status_t status;
 
     sort = query->sort;
     query->sort = NOTMUCH_SORT_UNSORTED;
-    messages = notmuch_query_search_messages (query);
+    status = notmuch_query_search_messages_st (query, &messages);
+    if (status)
+	return 0;
+
     query->sort = sort;
     if (messages == NULL)
 	return 0;
-- 
2.1.4

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

* [PATCH 05/10] lib: note remaining uses of deprecated message search API
  2015-06-07 15:01 update cli/lib to use new notmuch_query_search_* api David Bremner
                   ` (3 preceding siblings ...)
  2015-06-07 15:01 ` [PATCH 04/10] lib: remove use of notmuch_query_search_messages from query.cc David Bremner
@ 2015-06-07 15:01 ` David Bremner
  2015-06-07 15:01 ` [PATCH 06/10] test: move backup_database and restore_database to library David Bremner
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 13+ messages in thread
From: David Bremner @ 2015-06-07 15:01 UTC (permalink / raw)
  To: notmuch

The two remaining cases in the lib 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/thread.cc   | 2 ++
 2 files changed, 4 insertions(+)

diff --git a/lib/database.cc b/lib/database.cc
index 78a24f7..15619c3 100644
--- a/lib/database.cc
+++ b/lib/database.cc
@@ -1388,6 +1388,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/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))
-- 
2.1.4

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

* [PATCH 06/10] test: move backup_database and restore_database to library
  2015-06-07 15:01 update cli/lib to use new notmuch_query_search_* api David Bremner
                   ` (4 preceding siblings ...)
  2015-06-07 15:01 ` [PATCH 05/10] lib: note remaining uses of deprecated message search API David Bremner
@ 2015-06-07 15:01 ` David Bremner
  2015-06-07 15:02 ` [PATCH 07/10] lib: constify argument to notmuch_database_status_string David Bremner
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 13+ messages in thread
From: David Bremner @ 2015-06-07 15:01 UTC (permalink / raw)
  To: notmuch

The plan is to re-use them in testing the same errors from the CLI
---
 test/T560-lib-error.sh  | 10 ----------
 test/test-lib-common.sh | 14 ++++++++++++++
 2 files changed, 14 insertions(+), 10 deletions(-)

diff --git a/test/T560-lib-error.sh b/test/T560-lib-error.sh
index c99b17e..36607c3 100755
--- a/test/T560-lib-error.sh
+++ b/test/T560-lib-error.sh
@@ -3,16 +3,6 @@ test_description="error reporting for library"
 
 . ./test-lib.sh
 
-backup_database () {
-    rm -rf notmuch-dir-backup
-    cp -pR ${MAIL_DIR}/.notmuch notmuch-dir-backup
-}
-restore_database () {
-    rm -rf ${MAIL_DIR}/.notmuch
-    cp -pR notmuch-dir-backup ${MAIL_DIR}/.notmuch
-}
-
-
 add_email_corpus
 
 test_expect_success "building database" "NOTMUCH_NEW"
diff --git a/test/test-lib-common.sh b/test/test-lib-common.sh
index f99ed11..0d9c839 100644
--- a/test/test-lib-common.sh
+++ b/test/test-lib-common.sh
@@ -34,6 +34,20 @@ find_notmuch_path ()
     done
 }
 
+backup_database () {
+    test_name=$(basename $0 .sh)
+    rm -rf notmuch-dir-backup."$test_name"
+    cp -pR ${MAIL_DIR}/.notmuch notmuch-dir-backup."${test_name}"
+}
+
+restore_database () {
+    test_name=$(basename $0 .sh)
+    rm -rf ${MAIL_DIR}/.notmuch
+    cp -pR notmuch-dir-backup."${test_name}" ${MAIL_DIR}/.notmuch
+}
+
+
+
 # Test the binaries we have just built.  The tests are kept in
 # test/ subdirectory and are run in 'trash directory' subdirectory.
 TEST_DIRECTORY=$(pwd)
-- 
2.1.4

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

* [PATCH 07/10] lib: constify argument to notmuch_database_status_string
  2015-06-07 15:01 update cli/lib to use new notmuch_query_search_* api David Bremner
                   ` (5 preceding siblings ...)
  2015-06-07 15:01 ` [PATCH 06/10] test: move backup_database and restore_database to library David Bremner
@ 2015-06-07 15:02 ` David Bremner
  2015-09-04 11:28   ` David Bremner
  2015-06-07 15:02 ` [PATCH 08/10] cli: add utility routine to print error status David Bremner
                   ` (3 subsequent siblings)
  10 siblings, 1 reply; 13+ messages in thread
From: David Bremner @ 2015-06-07 15:02 UTC (permalink / raw)
  To: notmuch

We don't modify the database struct, so no harm in committing to that.
---
 lib/database.cc | 2 +-
 lib/notmuch.h   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/database.cc b/lib/database.cc
index 15619c3..3ef8eaa 100644
--- a/lib/database.cc
+++ b/lib/database.cc
@@ -2578,7 +2578,7 @@ notmuch_database_get_all_tags (notmuch_database_t *db)
 }
 
 const char *
-notmuch_database_status_string (notmuch_database_t *notmuch)
+notmuch_database_status_string (const notmuch_database_t *notmuch)
 {
     return notmuch->status_string;
 }
diff --git a/lib/notmuch.h b/lib/notmuch.h
index 46115c8..56d5ac4 100644
--- a/lib/notmuch.h
+++ b/lib/notmuch.h
@@ -308,7 +308,7 @@ notmuch_database_open_verbose (const char *path,
  *
  */
 const char *
-notmuch_database_status_string (notmuch_database_t *notmuch);
+notmuch_database_status_string (const notmuch_database_t *notmuch);
 
 /**
  * Commit changes and close the given notmuch database.
-- 
2.1.4

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

* [PATCH 08/10] cli: add utility routine to print error status.
  2015-06-07 15:01 update cli/lib to use new notmuch_query_search_* api David Bremner
                   ` (6 preceding siblings ...)
  2015-06-07 15:02 ` [PATCH 07/10] lib: constify argument to notmuch_database_status_string David Bremner
@ 2015-06-07 15:02 ` David Bremner
  2015-06-07 15:02 ` [PATCH 09/10] cli/count: update to use notmuch_query_search_messages_st David Bremner
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 13+ messages in thread
From: David Bremner @ 2015-06-07 15:02 UTC (permalink / raw)
  To: notmuch

No attention to formatting here, initially just focus on getting the
relevant strings out of the library.
---
 Makefile.local   |  1 +
 notmuch-client.h |  9 +++++++++
 status.c         | 21 +++++++++++++++++++++
 3 files changed, 31 insertions(+)
 create mode 100644 status.c

diff --git a/Makefile.local b/Makefile.local
index 6d54742..4de39b8 100644
--- a/Makefile.local
+++ b/Makefile.local
@@ -271,6 +271,7 @@ dataclean: distclean
 notmuch_client_srcs =		\
 	command-line-arguments.c\
 	debugger.c		\
+	status.c		\
 	gmime-filter-reply.c	\
 	hooks.c			\
 	notmuch.c		\
diff --git a/notmuch-client.h b/notmuch-client.h
index 78680aa..0f52038 100644
--- a/notmuch-client.h
+++ b/notmuch-client.h
@@ -465,6 +465,15 @@ notmuch_database_dump (notmuch_database_t *notmuch,
 		       dump_format_t output_format,
 		       notmuch_bool_t gzip_output);
 
+/* If status is non-zero (i.e. error) print appropriate
+   messages to stderr.
+*/
+
+notmuch_status_t
+print_status_query (const char *loc,
+		    const notmuch_query_t *query,
+		    notmuch_status_t status);
+
 #include "command-line-arguments.h"
 extern const notmuch_opt_desc_t  notmuch_shared_options [];
 void notmuch_process_shared_options (const char* subcommand_name);
diff --git a/status.c b/status.c
new file mode 100644
index 0000000..8fa81cb
--- /dev/null
+++ b/status.c
@@ -0,0 +1,21 @@
+#include "notmuch-client.h"
+
+notmuch_status_t
+print_status_query (const char *loc,
+		    const notmuch_query_t *query,
+		    notmuch_status_t status)
+{
+    if (status) {
+	const char *msg;
+	notmuch_database_t *notmuch;
+
+	fprintf (stderr, "%s: %s\n", loc,
+		 notmuch_status_to_string (status));
+
+	notmuch = notmuch_query_get_database (query);
+	msg = notmuch_database_status_string (notmuch);
+	if (msg)
+	    fputs (msg, stderr);
+    }
+    return status;
+}
-- 
2.1.4

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

* [PATCH 09/10] cli/count: update to use notmuch_query_search_messages_st
  2015-06-07 15:01 update cli/lib to use new notmuch_query_search_* api David Bremner
                   ` (7 preceding siblings ...)
  2015-06-07 15:02 ` [PATCH 08/10] cli: add utility routine to print error status David Bremner
@ 2015-06-07 15:02 ` David Bremner
  2015-06-07 15:02 ` [PATCH 10/10] cli: convert remainder of CLI to n_q_search_{messages,threads}_st David Bremner
  2015-08-04  7:14 ` update cli/lib to use new notmuch_query_search_* api David Bremner
  10 siblings, 0 replies; 13+ messages in thread
From: David Bremner @ 2015-06-07 15:02 UTC (permalink / raw)
  To: notmuch

This brings back status information that may have been hidden by the
great library logging conversion.
---
 notmuch-count.c    | 16 ++++++++++------
 test/T060-count.sh | 30 ++++++++++++++++++++++++++++++
 2 files changed, 40 insertions(+), 6 deletions(-)

diff --git a/notmuch-count.c b/notmuch-count.c
index 57a88a8..25b05df 100644
--- a/notmuch-count.c
+++ b/notmuch-count.c
@@ -33,17 +33,18 @@ enum {
     EXCLUDE_FALSE,
 };
 
-static unsigned int
+static int
 count_files (notmuch_query_t *query)
 {
     notmuch_messages_t *messages;
     notmuch_message_t *message;
     notmuch_filenames_t *filenames;
-    unsigned int count = 0;
+    notmuch_status_t status;
+    int count = 0;
 
-    messages = notmuch_query_search_messages (query);
-    if (messages == NULL)
-	return 0;
+    status = notmuch_query_search_messages_st (query, &messages);
+    if (print_status_query ("notmuch count", query, status))
+	return -1;
 
     for (;
 	 notmuch_messages_valid (messages);
@@ -71,6 +72,7 @@ print_count (notmuch_database_t *notmuch, const char *query_str,
 {
     notmuch_query_t *query;
     size_t i;
+    int count;
 
     query = notmuch_query_create (notmuch, query_str);
     if (query == NULL) {
@@ -89,7 +91,9 @@ print_count (notmuch_database_t *notmuch, const char *query_str,
 	printf ("%u\n", notmuch_query_count_threads (query));
 	break;
     case OUTPUT_FILES:
-	printf ("%u\n", count_files (query));
+	count = count_files (query);
+	if (count >= 0)
+	    printf ("%u\n", count);
 	break;
     }
 
diff --git a/test/T060-count.sh b/test/T060-count.sh
index da86c8c..973a42d 100755
--- a/test/T060-count.sh
+++ b/test/T060-count.sh
@@ -93,5 +93,35 @@ notmuch count --output=messages >>EXPECTED
 notmuch count --output=messages tag:inbox >>EXPECTED
 test_expect_equal_file EXPECTED OUTPUT
 
+backup_database
+test_begin_subtest "error message for database open"
+dd if=/dev/zero of="${MAIL_DIR}/.notmuch/xapian/postlist.DB" count=3
+notmuch count '*' 2>OUTPUT 1>/dev/null
+output=$(sed 's/^\(A Xapian exception [^:]*\):.*$/\1/' OUTPUT)
+test_expect_equal "${output}" "A Xapian exception occurred opening database"
+restore_database
+
+cat <<EOF > count-files.gdb
+set breakpoint pending on
+break count_files
+commands
+shell cp /dev/null ${MAIL_DIR}/.notmuch/xapian/postlist.DB
+continue
+end
+run
+EOF
+
+backup_database
+test_begin_subtest "error message from query_search_messages"
+gdb --batch-silent --return-child-result -x count-files.gdb \
+    --args notmuch count --output=files '*' 2>OUTPUT 1>/dev/null
+cat <<EOF > EXPECTED
+notmuch count: A Xapian exception occurred
+A Xapian exception occurred performing query
+Query string was: *
+EOF
+sed 's/^\(A Xapian exception [^:]*\):.*$/\1/' < OUTPUT > OUTPUT.clean
+test_expect_equal_file EXPECTED OUTPUT.clean
+restore_database
 
 test_done
-- 
2.1.4

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

* [PATCH 10/10] cli: convert remainder of CLI to n_q_search_{messages,threads}_st
  2015-06-07 15:01 update cli/lib to use new notmuch_query_search_* api David Bremner
                   ` (8 preceding siblings ...)
  2015-06-07 15:02 ` [PATCH 09/10] cli/count: update to use notmuch_query_search_messages_st David Bremner
@ 2015-06-07 15:02 ` David Bremner
  2015-08-04  7:14 ` update cli/lib to use new notmuch_query_search_* api David Bremner
  10 siblings, 0 replies; 13+ messages in thread
From: David Bremner @ 2015-06-07 15:02 UTC (permalink / raw)
  To: notmuch

I think it would be no real problem to cut and paste the gdb based
error message test from count to the other clients modified here, but
I'm not currently convinced it's worth the trouble since the code path
being tested is almost the the same, and the tests are relatively
heavyweight.
---
 notmuch-dump.c   |  7 ++++++-
 notmuch-reply.c  | 20 +++++++++++++++++---
 notmuch-search.c | 15 +++++++++------
 notmuch-show.c   | 10 +++++++---
 notmuch-tag.c    |  8 +++++++-
 5 files changed, 46 insertions(+), 14 deletions(-)

diff --git a/notmuch-dump.c b/notmuch-dump.c
index fab22bd..c965a4f 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 (print_status_query ("notmuch dump", query, 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 4464741..602bdaa 100644
--- a/notmuch-reply.c
+++ b/notmuch-reply.c
@@ -606,8 +606,13 @@ 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 (print_status_query ("notmuch reply", query, status))
+	return 1;
+
+    for (;
 	 notmuch_messages_valid (messages);
 	 notmuch_messages_move_to_next (messages))
     {
@@ -650,13 +655,17 @@ notmuch_reply_format_sprinter(void *ctx,
     notmuch_messages_t *messages;
     notmuch_message_t *message;
     mime_node_t *node;
+    notmuch_status_t status;
 
     if (notmuch_query_count_messages (query) != 1) {
 	fprintf (stderr, "Error: search term did not match precisely one message.\n");
 	return 1;
     }
 
-    messages = notmuch_query_search_messages (query);
+    status = notmuch_query_search_messages_st (query, &messages);
+    if (print_status_query ("notmuch reply", query, status))
+	return 1;
+
     message = notmuch_messages_get (messages);
     if (mime_node_open (ctx, message, &(params->crypto), &node) != NOTMUCH_STATUS_SUCCESS)
 	return 1;
@@ -698,8 +707,13 @@ 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;
+
+    status = notmuch_query_search_messages_st (query, &messages);
+    if (print_status_query ("notmuch reply", query, status))
+	return 1;
 
-    for (messages = notmuch_query_search_messages (query);
+    for (;
 	 notmuch_messages_valid (messages);
 	 notmuch_messages_move_to_next (messages))
     {
diff --git a/notmuch-search.c b/notmuch-search.c
index b89a17e..9887ebf 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,8 +119,8 @@ 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 (print_status_query("notmuch search", ctx->query, status))
 	return 1;
 
     format->begin_list (format);
@@ -412,6 +413,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,8 +421,8 @@ 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 (print_status_query ("notmuch search", ctx->query, status))
 	return 1;
 
     format->begin_list (format);
@@ -508,8 +510,9 @@ 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 (print_status_query ("notmuch search", query, status))
 	    return 1;
 
 	tags = notmuch_messages_collect_tags (messages);
diff --git a/notmuch-show.c b/notmuch-show.c
index b80933a..aff39b0 100644
--- a/notmuch-show.c
+++ b/notmuch-show.c
@@ -982,13 +982,17 @@ do_show_single (void *ctx,
 {
     notmuch_messages_t *messages;
     notmuch_message_t *message;
+    notmuch_status_t status;
 
     if (notmuch_query_count_messages (query) != 1) {
 	fprintf (stderr, "Error: search term did not match precisely one message.\n");
 	return 1;
     }
 
-    messages = notmuch_query_search_messages (query);
+    status = notmuch_query_search_messages_st (query, &messages);
+    if (print_status_query ("notmuch show", query, status))
+	return 1;
+
     message = notmuch_messages_get (messages);
 
     if (message == NULL) {
@@ -1015,8 +1019,8 @@ 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 (print_status_query ("notmuch show", query, status))
 	return 1;
 
     sp->begin_list (sp);
diff --git a/notmuch-tag.c b/notmuch-tag.c
index 38d99aa..19108d9 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 (print_status_query ("notmuch tag", query, 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] 13+ messages in thread

* Re: update cli/lib to use new notmuch_query_search_* api
  2015-06-07 15:01 update cli/lib to use new notmuch_query_search_* api David Bremner
                   ` (9 preceding siblings ...)
  2015-06-07 15:02 ` [PATCH 10/10] cli: convert remainder of CLI to n_q_search_{messages,threads}_st David Bremner
@ 2015-08-04  7:14 ` David Bremner
  10 siblings, 0 replies; 13+ messages in thread
From: David Bremner @ 2015-08-04  7:14 UTC (permalink / raw)
  To: notmuch

David Bremner <david@tethera.net> writes:

> I was already to push the first few patches of
>
>   id:1425756182-28468-1-git-send-email-david@tethera.net
>
> When I realized there was probably a reason that no-one had reviewed
> patch 3/5. After breaking up that ball of mud, one thing led to
> another, and deprecating the old API and updating to the new API is up
> to 10 patches.

It's kind of a dirty trick to get feedback on the rest of the series,
but I pushed the part that generates a bunch of compilation warnings ;).

d

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

* Re: [PATCH 07/10] lib: constify argument to notmuch_database_status_string
  2015-06-07 15:02 ` [PATCH 07/10] lib: constify argument to notmuch_database_status_string David Bremner
@ 2015-09-04 11:28   ` David Bremner
  0 siblings, 0 replies; 13+ messages in thread
From: David Bremner @ 2015-09-04 11:28 UTC (permalink / raw)
  To: notmuch

David Bremner <david@tethera.net> writes:

> We don't modify the database struct, so no harm in committing to that.

The next 4 patches in this series seemed trivial to me, so I pushed them

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

end of thread, other threads:[~2015-09-04 11:29 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-06-07 15:01 update cli/lib to use new notmuch_query_search_* api David Bremner
2015-06-07 15:01 ` [PATCH 01/10] lib: define NOTMUCH_DEPRECATED macro, document its use David Bremner
2015-06-07 15:01 ` [PATCH 02/10] lib: deprecate notmuch_query_search_{threads, messages} David Bremner
2015-06-07 15:01 ` [PATCH 03/10] lib: add public accessor for database from query David Bremner
2015-06-07 15:01 ` [PATCH 04/10] lib: remove use of notmuch_query_search_messages from query.cc David Bremner
2015-06-07 15:01 ` [PATCH 05/10] lib: note remaining uses of deprecated message search API David Bremner
2015-06-07 15:01 ` [PATCH 06/10] test: move backup_database and restore_database to library David Bremner
2015-06-07 15:02 ` [PATCH 07/10] lib: constify argument to notmuch_database_status_string David Bremner
2015-09-04 11:28   ` David Bremner
2015-06-07 15:02 ` [PATCH 08/10] cli: add utility routine to print error status David Bremner
2015-06-07 15:02 ` [PATCH 09/10] cli/count: update to use notmuch_query_search_messages_st David Bremner
2015-06-07 15:02 ` [PATCH 10/10] cli: convert remainder of CLI to n_q_search_{messages,threads}_st David Bremner
2015-08-04  7:14 ` update cli/lib to use new notmuch_query_search_* 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).