diff options
| author | David Bremner <david@tethera.net> | 2014-12-26 09:01:01 +0100 |
|---|---|---|
| committer | David Bremner <david@tethera.net> | 2015-03-29 00:34:15 +0100 |
| commit | b53e1a2da720e9a0efd815b92f0a54dc2f644ffc (patch) | |
| tree | 97aae74e52980f23b1bacd67cd9611af9b3d2621 | |
| parent | 84d3b15d251623cbb66e5eca7ddb8d61aa596d33 (diff) | |
lib: add a log function with output to a string in notmuch_database_t
In principle in the future this could do something fancier than
asprintf.
| -rw-r--r-- | lib/database-private.h | 4 | ||||
| -rw-r--r-- | lib/database.cc | 24 | ||||
| -rw-r--r-- | lib/notmuch-private.h | 4 | ||||
| -rw-r--r-- | lib/notmuch.h | 7 |
4 files changed, 39 insertions, 0 deletions
diff --git a/lib/database-private.h b/lib/database-private.h index 6d6fa2c9..24243db2 100644 --- a/lib/database-private.h +++ b/lib/database-private.h @@ -154,6 +154,10 @@ struct _notmuch_database { unsigned int last_doc_id; uint64_t last_thread_id; + /* error reporting; this value persists only until the + * next library call. May be NULL */ + char *status_string; + Xapian::QueryParser *query_parser; Xapian::TermGenerator *term_gen; Xapian::ValueRangeProcessor *value_range_processor; diff --git a/lib/database.cc b/lib/database.cc index 4173b681..aa06b3ef 100644 --- a/lib/database.cc +++ b/lib/database.cc @@ -348,6 +348,23 @@ notmuch_status_to_string (notmuch_status_t status) } } +void +_notmuch_database_log (notmuch_database_t *notmuch, + const char *format, + ...) +{ + va_list va_args; + + va_start (va_args, format); + + if (notmuch->status_string) + talloc_free (notmuch->status_string); + + notmuch->status_string = talloc_vasprintf (notmuch, format, va_args); + + va_end (va_args); +} + static void find_doc_ids_for_term (notmuch_database_t *notmuch, const char *term, @@ -863,6 +880,7 @@ notmuch_database_open_verbose (const char *path, notmuch = talloc_zero (NULL, notmuch_database_t); notmuch->exception_reported = FALSE; + notmuch->status_string = NULL; notmuch->path = talloc_strdup (notmuch, path); if (notmuch->path[strlen (notmuch->path) - 1] == '/') @@ -2552,3 +2570,9 @@ notmuch_database_get_all_tags (notmuch_database_t *db) return NULL; } } + +const char * +notmuch_database_status_string (notmuch_database_t *notmuch) +{ + return notmuch->status_string; +} diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h index 8a1f2fab..7cb6fd49 100644 --- a/lib/notmuch-private.h +++ b/lib/notmuch-private.h @@ -190,6 +190,10 @@ _notmuch_message_id_compressed (void *ctx, const char *message_id); notmuch_status_t _notmuch_database_ensure_writable (notmuch_database_t *notmuch); +void +_notmuch_database_log (notmuch_database_t *notmuch, + const char *format, ...); + const char * _notmuch_database_relative_path (notmuch_database_t *notmuch, const char *path); diff --git a/lib/notmuch.h b/lib/notmuch.h index c671d822..20c4e019 100644 --- a/lib/notmuch.h +++ b/lib/notmuch.h @@ -302,6 +302,13 @@ notmuch_database_open_verbose (const char *path, char **error_message); /** + * Retrieve last status string for given database. + * + */ +const char * +notmuch_database_status_string (notmuch_database_t *notmuch); + +/** * Commit changes and close the given notmuch database. * * After notmuch_database_close has been called, calls to other |
