]> git.notmuchmail.org Git - notmuch/commitdiff
lib: add a log function with output to a string in notmuch_database_t
authorDavid Bremner <david@tethera.net>
Fri, 26 Dec 2014 08:01:01 +0000 (09:01 +0100)
committerDavid Bremner <david@tethera.net>
Sat, 28 Mar 2015 23:34:15 +0000 (00:34 +0100)
In principle in the future this could do something fancier than
asprintf.

lib/database-private.h
lib/database.cc
lib/notmuch-private.h
lib/notmuch.h

index 6d6fa2c9f6bd56af79a7039d0da9d3694aa8b942..24243db2e4fd38577a3aae8840003cbfef3ec637 100644 (file)
@@ -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;
index 4173b68162ac8be100ece4ac7497f56bee3ada18..aa06b3efb013c96676998e10de3ca0ed02dcf9ab 100644 (file)
@@ -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;
+}
index 8a1f2fab77af7c5d9102babdf7625394ed8a07c0..7cb6fd49d890bf9b5f718c4bf36a9e32bdc0aad2 100644 (file)
@@ -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);
index c671d8229b39ba4700e72d9160b7382e97653382..20c4e0190c5cdc2f9e5d5464e9ab67192d424534 100644 (file)
@@ -301,6 +301,13 @@ notmuch_database_open_verbose (const char *path,
                               notmuch_database_t **database,
                               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.
  *