]> git.cworth.org Git - notmuch/commitdiff
Merge branch 'release'
authorDavid Bremner <david@tethera.net>
Sat, 15 May 2021 12:10:58 +0000 (09:10 -0300)
committerDavid Bremner <david@tethera.net>
Sat, 15 May 2021 12:10:58 +0000 (09:10 -0300)
36 files changed:
Makefile.local
NEWS
bindings/ruby/defs.h
bindings/ruby/directory.c
bindings/ruby/threads.c
gmime-filter-reply.c
gmime-filter-reply.h
lib/Makefile.local
lib/add-message.cc
lib/database-private.h
lib/index.cc
lib/init.cc [new file with mode: 0644]
lib/message-file.c
lib/message.cc
lib/notmuch-private.h
lib/open.cc
notmuch-client-init.c [new file with mode: 0644]
notmuch-client.h
notmuch-config.c
notmuch-insert.c
notmuch-new.c
notmuch-reindex.c
notmuch-tag.c
notmuch.c
performance-test/README
performance-test/perf-test-lib.sh
test/T310-emacs.sh
test/T350-crypto.sh
test/T355-smime.sh
test/T357-index-decryption.sh
test/T395-ruby.sh
test/T450-emacs-show.sh
test/T460-emacs-tree.sh
test/T730-emacs-forwarding.sh
test/test-lib.sh
vim/notmuch.vim

index bbb8f0b61a3fab43819e906ad3a2a9b3195b65f2..e12b94cd6f668bfc830070ec24d924ff8941bebf 100644 (file)
@@ -231,6 +231,7 @@ notmuch_client_srcs =               \
        gmime-filter-reply.c    \
        hooks.c                 \
        notmuch.c               \
+       notmuch-client-init.c   \
        notmuch-compact.c       \
        notmuch-config.c        \
        notmuch-count.c         \
diff --git a/NEWS b/NEWS
index e1fa2d73ae027c8e2dfa666b3dcbde5be789ca5a..c0ae6afe9c7b4307a15350673c0714db0f53879c 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,11 @@
+Notmuch 0.33 (UNRELEASED)
+=========================
+
+Vim
+---
+
+Respect excluded tags when showing a thread.
+
 Notmuch 0.32.1 (2021-05-15)
 ===========================
 
index 48544ca2a4acbe57a48630957e9dd059de504f69..46e2caf8a0ee54fbb08b4fbb9c850853e95a4809 100644 (file)
@@ -55,77 +55,39 @@ extern ID ID_db_mode;
 # define RSTRING_PTR(v) (RSTRING((v))->ptr)
 #endif /* !defined (RSTRING_PTR) */
 
-#define Data_Get_Notmuch_Database(obj, ptr)                    \
+#define Data_Get_Notmuch_Object(obj, type, message, ptr)       \
     do {                                                       \
-       Check_Type ((obj), T_DATA);                             \
-       if (DATA_PTR ((obj)) == NULL)                           \
-       rb_raise (rb_eRuntimeError, "database closed");         \
-       Data_Get_Struct ((obj), notmuch_database_t, (ptr));     \
+       Data_Get_Struct ((obj), type, (ptr));                   \
+       if (!(ptr))                                             \
+       rb_raise (rb_eRuntimeError, (message));                 \
     } while (0)
 
-#define Data_Get_Notmuch_Directory(obj, ptr)                   \
-    do {                                                       \
-       Check_Type ((obj), T_DATA);                             \
-       if (DATA_PTR ((obj)) == NULL)                           \
-       rb_raise (rb_eRuntimeError, "directory destroyed");     \
-       Data_Get_Struct ((obj), notmuch_directory_t, (ptr));    \
-    } while (0)
+#define Data_Get_Notmuch_Database(obj, ptr) \
+    Data_Get_Notmuch_Object ((obj), notmuch_database_t, "database closed", (ptr))
 
-#define Data_Get_Notmuch_FileNames(obj, ptr)                   \
-    do {                                                       \
-       Check_Type ((obj), T_DATA);                             \
-       if (DATA_PTR ((obj)) == NULL)                           \
-       rb_raise (rb_eRuntimeError, "filenames destroyed");     \
-       Data_Get_Struct ((obj), notmuch_filenames_t, (ptr));    \
-    } while (0)
+#define Data_Get_Notmuch_Directory(obj, ptr) \
+    Data_Get_Notmuch_Object ((obj), notmuch_directory_t, "directory destroyed", (ptr))
 
-#define Data_Get_Notmuch_Query(obj, ptr)                       \
-    do {                                                       \
-       Check_Type ((obj), T_DATA);                             \
-       if (DATA_PTR ((obj)) == NULL)                           \
-       rb_raise (rb_eRuntimeError, "query destroyed");         \
-       Data_Get_Struct ((obj), notmuch_query_t, (ptr));        \
-    } while (0)
+#define Data_Get_Notmuch_FileNames(obj, ptr) \
+    Data_Get_Notmuch_Object ((obj), notmuch_filenames_t, "filenames destroyed", (ptr))
 
-#define Data_Get_Notmuch_Threads(obj, ptr)                     \
-    do {                                                       \
-       Check_Type ((obj), T_DATA);                             \
-       if (DATA_PTR ((obj)) == NULL)                           \
-       rb_raise (rb_eRuntimeError, "threads destroyed");       \
-       Data_Get_Struct ((obj), notmuch_threads_t, (ptr));      \
-    } while (0)
+#define Data_Get_Notmuch_Query(obj, ptr) \
+    Data_Get_Notmuch_Object ((obj), notmuch_query_t, "query destroyed", (ptr))
 
-#define Data_Get_Notmuch_Messages(obj, ptr)                    \
-    do {                                                       \
-       Check_Type ((obj), T_DATA);                             \
-       if (DATA_PTR ((obj)) == NULL)                           \
-       rb_raise (rb_eRuntimeError, "messages destroyed");      \
-       Data_Get_Struct ((obj), notmuch_messages_t, (ptr));     \
-    } while (0)
+#define Data_Get_Notmuch_Threads(obj, ptr) \
+    Data_Get_Notmuch_Object ((obj), notmuch_threads_t, "threads destroyed", (ptr))
 
-#define Data_Get_Notmuch_Thread(obj, ptr)                      \
-    do {                                                       \
-       Check_Type ((obj), T_DATA);                             \
-       if (DATA_PTR ((obj)) == NULL)                           \
-       rb_raise (rb_eRuntimeError, "thread destroyed");        \
-       Data_Get_Struct ((obj), notmuch_thread_t, (ptr));       \
-    } while (0)
+#define Data_Get_Notmuch_Messages(obj, ptr) \
+    Data_Get_Notmuch_Object ((obj), notmuch_messages_t, "messages destroyed", (ptr))
 
-#define Data_Get_Notmuch_Message(obj, ptr)                     \
-    do {                                                       \
-       Check_Type ((obj), T_DATA);                             \
-       if (DATA_PTR ((obj)) == NULL)                           \
-       rb_raise (rb_eRuntimeError, "message destroyed");       \
-       Data_Get_Struct ((obj), notmuch_message_t, (ptr));      \
-    } while (0)
+#define Data_Get_Notmuch_Thread(obj, ptr) \
+    Data_Get_Notmuch_Object ((obj), notmuch_thread_t, "thread destroyed", (ptr))
 
-#define Data_Get_Notmuch_Tags(obj, ptr)                        \
-    do {                                               \
-       Check_Type ((obj), T_DATA);                     \
-       if (DATA_PTR ((obj)) == NULL)                   \
-       rb_raise (rb_eRuntimeError, "tags destroyed");  \
-       Data_Get_Struct ((obj), notmuch_tags_t, (ptr)); \
-    } while (0)
+#define Data_Get_Notmuch_Message(obj, ptr) \
+    Data_Get_Notmuch_Object ((obj), notmuch_message_t, "message destroyed", (ptr))
+
+#define Data_Get_Notmuch_Tags(obj, ptr) \
+    Data_Get_Notmuch_Object ((obj), notmuch_tags_t, "tags destroyed", (ptr))
 
 /* status.c */
 void
index 0f37b3910042426219ae7cdf7137ec1b017cfb11..fe5fc46d1145328676d574661dc0089a267cf0e3 100644 (file)
@@ -30,7 +30,7 @@ notmuch_rb_directory_destroy (VALUE self)
 {
     notmuch_directory_t *dir;
 
-    Data_Get_Struct (self, notmuch_directory_t, dir);
+    Data_Get_Notmuch_Directory (self, dir);
 
     notmuch_directory_destroy (dir);
     DATA_PTR (self) = NULL;
index ed403a8f1f3db30e88d8fd030991ae1b62b1c9e6..5885f5651ceeb100b3011557d462c8bdba29d586 100644 (file)
@@ -30,7 +30,7 @@ notmuch_rb_threads_destroy (VALUE self)
 {
     notmuch_threads_t *threads;
 
-    Data_Get_Struct (self, notmuch_threads_t, threads);
+    Data_Get_Notmuch_Threads (self, threads);
 
     notmuch_threads_destroy (threads);
     DATA_PTR (self) = NULL;
index 2b0676698b8ff7225b164c9db52ab5ad5b5ea314..35349cc8170fdd7abcaa08684e83320eb9f1df08 100644 (file)
@@ -43,29 +43,31 @@ static void filter_reset (GMimeFilter *filter);
 
 
 static GMimeFilterClass *parent_class = NULL;
+static GType type = 0;
+static const GTypeInfo info = {
+    .class_size = sizeof (GMimeFilterReplyClass),
+    .base_init = NULL,
+    .base_finalize = NULL,
+    .class_init = (GClassInitFunc) g_mime_filter_reply_class_init,
+    .class_finalize = NULL,
+    .class_data = NULL,
+    .instance_size = sizeof (GMimeFilterReply),
+    .n_preallocs = 0,
+    .instance_init = (GInstanceInitFunc) g_mime_filter_reply_init,
+    .value_table = NULL,
+};
+
+
+void
+g_mime_filter_reply_module_init (void)
+{
+    type = g_type_register_static (GMIME_TYPE_FILTER, "GMimeFilterReply", &info, (GTypeFlags) 0);
+    parent_class = (GMimeFilterClass *) g_type_class_ref (GMIME_TYPE_FILTER);
+}
 
 GType
 g_mime_filter_reply_get_type (void)
 {
-    static GType type = 0;
-
-    if (! type) {
-       static const GTypeInfo info = {
-           .class_size = sizeof (GMimeFilterReplyClass),
-           .base_init = NULL,
-           .base_finalize = NULL,
-           .class_init = (GClassInitFunc) g_mime_filter_reply_class_init,
-           .class_finalize = NULL,
-           .class_data = NULL,
-           .instance_size = sizeof (GMimeFilterReply),
-           .n_preallocs = 0,
-           .instance_init = (GInstanceInitFunc) g_mime_filter_reply_init,
-           .value_table = NULL,
-       };
-
-       type = g_type_register_static (GMIME_TYPE_FILTER, "GMimeFilterReply", &info, (GTypeFlags) 0);
-    }
-
     return type;
 }
 
@@ -76,8 +78,6 @@ g_mime_filter_reply_class_init (GMimeFilterReplyClass *klass, unused (void *clas
     GObjectClass *object_class = G_OBJECT_CLASS (klass);
     GMimeFilterClass *filter_class = GMIME_FILTER_CLASS (klass);
 
-    parent_class = (GMimeFilterClass *) g_type_class_ref (GMIME_TYPE_FILTER);
-
     object_class->finalize = g_mime_filter_reply_finalize;
 
     filter_class->copy = filter_copy;
index 7cdefcd1f127ff45e5ca9cbd63bf0f541816e1c9..988fe2d6e8c5122fcbc523e8ceefdab4e38bd38e 100644 (file)
@@ -21,6 +21,8 @@
 
 #include <gmime/gmime-filter.h>
 
+void g_mime_filter_reply_module_init (void);
+
 G_BEGIN_DECLS
 
 #define GMIME_TYPE_FILTER_REPLY            (g_mime_filter_reply_get_type ())
index 01cbb3f2821c8e0a1e0145192e2e3368b625d6c7..e2d4b91dcaf2add44978fa28ed49dbadcbf8eaa3 100644 (file)
@@ -62,7 +62,8 @@ libnotmuch_cxx_srcs =         \
        $(dir)/thread-fp.cc     \
        $(dir)/features.cc      \
        $(dir)/prefix.cc        \
-       $(dir)/open.cc
+       $(dir)/open.cc          \
+       $(dir)/init.cc
 
 libnotmuch_modules := $(libnotmuch_c_srcs:.c=.o) $(libnotmuch_cxx_srcs:.cc=.o)
 
index 0c34d31822bb48a654631d3d41015c905e1fe07a..d4a00b175392710579f7d437d4782cb340ac8a4b 100644 (file)
@@ -40,17 +40,14 @@ parse_references (void *ctx,
 static const char *
 _notmuch_database_generate_thread_id (notmuch_database_t *notmuch)
 {
-    /* 16 bytes (+ terminator) for hexadecimal representation of
-     * a 64-bit integer. */
-    static char thread_id[17];
 
     notmuch->last_thread_id++;
 
-    sprintf (thread_id, "%016" PRIx64, notmuch->last_thread_id);
+    sprintf (notmuch->thread_id_str, "%016" PRIx64, notmuch->last_thread_id);
 
-    notmuch->writable_xapian_db->set_metadata ("last_thread_id", thread_id);
+    notmuch->writable_xapian_db->set_metadata ("last_thread_id", notmuch->thread_id_str);
 
-    return thread_id;
+    return notmuch->thread_id_str;
 }
 
 static char *
index 0d12ec1efde57b4862f1001facdbfafe3dec54cd..1a73dacc365f563134d123fe09d91668b45a6d1f 100644 (file)
@@ -206,6 +206,10 @@ struct _notmuch_database {
     enum _notmuch_features features;
 
     unsigned int last_doc_id;
+
+    /* 16 bytes (+ terminator) for hexadecimal representation of
+     * a 64-bit integer. */
+    char thread_id_str[17];
     uint64_t last_thread_id;
 
     /* error reporting; this value persists only until the
index 55c8372e3aa1c146913222369f7185cb6805531a..728bfb22ab69c4eef52795cf86d7971c7d42e2fe 100644 (file)
@@ -148,8 +148,6 @@ notmuch_filter_discard_non_term_class_init (NotmuchFilterDiscardNonTermClass *kl
     GObjectClass *object_class = G_OBJECT_CLASS (klass);
     GMimeFilterClass *filter_class = GMIME_FILTER_CLASS (klass);
 
-    parent_class = (GMimeFilterClass *) g_type_class_ref (GMIME_TYPE_FILTER);
-
     object_class->finalize = notmuch_filter_discard_non_term_finalize;
 
     filter_class->copy = filter_copy;
@@ -240,30 +238,33 @@ filter_reset (GMimeFilter *gmime_filter)
  *
  * Returns: a new #NotmuchFilterDiscardNonTerm filter.
  **/
+static GType type = 0;
+
+static const GTypeInfo info = {
+    .class_size = sizeof (NotmuchFilterDiscardNonTermClass),
+    .base_init = NULL,
+    .base_finalize = NULL,
+    .class_init = (GClassInitFunc) notmuch_filter_discard_non_term_class_init,
+    .class_finalize = NULL,
+    .class_data = NULL,
+    .instance_size = sizeof (NotmuchFilterDiscardNonTerm),
+    .n_preallocs = 0,
+    .instance_init = NULL,
+    .value_table = NULL,
+};
+
+void
+_notmuch_filter_init () {
+    type = g_type_register_static (GMIME_TYPE_FILTER, "NotmuchFilterDiscardNonTerm", &info,
+                                  (GTypeFlags) 0);
+    parent_class = (GMimeFilterClass *) g_type_class_ref (GMIME_TYPE_FILTER);
+}
+
 static GMimeFilter *
 notmuch_filter_discard_non_term_new (GMimeContentType *content_type)
 {
-    static GType type = 0;
     NotmuchFilterDiscardNonTerm *filter;
 
-    if (! type) {
-       static const GTypeInfo info = {
-           .class_size = sizeof (NotmuchFilterDiscardNonTermClass),
-           .base_init = NULL,
-           .base_finalize = NULL,
-           .class_init = (GClassInitFunc) notmuch_filter_discard_non_term_class_init,
-           .class_finalize = NULL,
-           .class_data = NULL,
-           .instance_size = sizeof (NotmuchFilterDiscardNonTerm),
-           .n_preallocs = 0,
-           .instance_init = NULL,
-           .value_table = NULL,
-       };
-
-       type = g_type_register_static (GMIME_TYPE_FILTER, "NotmuchFilterDiscardNonTerm", &info,
-                                      (GTypeFlags) 0);
-    }
-
     filter = (NotmuchFilterDiscardNonTerm *) g_object_new (type, NULL);
     filter->content_type = content_type;
     filter->state = 0;
diff --git a/lib/init.cc b/lib/init.cc
new file mode 100644 (file)
index 0000000..cf29200
--- /dev/null
@@ -0,0 +1,21 @@
+#include "notmuch-private.h"
+
+#include <mutex>
+
+static void do_init ()
+{
+    /* Initialize the GLib type system and threads */
+#if ! GLIB_CHECK_VERSION (2, 35, 1)
+    g_type_init ();
+#endif
+
+    g_mime_init ();
+    _notmuch_filter_init ();
+}
+
+void
+_notmuch_init ()
+{
+    static std::once_flag initialized;
+    std::call_once (initialized, do_init);
+}
index 9e9b387fcc697a8e8b3d13a8bbbd03147714ef58..647ccf3abedaaf52f95bcc44e9a3199de8d4b42d 100644 (file)
@@ -141,7 +141,6 @@ _notmuch_message_file_parse (notmuch_message_file_t *message)
 {
     GMimeParser *parser;
     notmuch_status_t status = NOTMUCH_STATUS_SUCCESS;
-    static int initialized = 0;
     bool is_mbox;
 
     if (message->message)
@@ -149,10 +148,7 @@ _notmuch_message_file_parse (notmuch_message_file_t *message)
 
     is_mbox = _is_mbox (message->stream);
 
-    if (! initialized) {
-       g_mime_init ();
-       initialized = 1;
-    }
+    _notmuch_init ();
 
     message->headers = g_hash_table_new_full (strcase_hash, strcase_equal,
                                              free, g_free);
index 42d56acb10e4ae80a3f36e92c2f6c644b03afd43..7af6ab82a721699ac7f09153724b9e8038484b2a 100644 (file)
@@ -68,7 +68,7 @@ struct maildir_flag_tag {
 };
 
 /* ASCII ordered table of Maildir flags and associated tags */
-static struct maildir_flag_tag flag2tag[] = {
+static const struct maildir_flag_tag flag2tag[] = {
     { 'D', "draft",   false },
     { 'F', "flagged", false },
     { 'P', "passed",  false },
index 10b1b0245b16d12b8caca6f0bb109a6cde3ba89a..093c29b1bbc5384198b90c351046a6a3b19200e1 100644 (file)
@@ -469,11 +469,18 @@ _notmuch_database_link_message_to_parents (notmuch_database_t *notmuch,
                                           const char **thread_id);
 /* index.cc */
 
+void
+_notmuch_filter_init ();
+
 notmuch_status_t
 _notmuch_message_index_file (notmuch_message_t *message,
                             notmuch_indexopts_t *indexopts,
                             notmuch_message_file_t *message_file);
 
+/* init.cc */
+void
+_notmuch_init ();
+
 /* messages.c */
 
 typedef struct _notmuch_message_node {
index 3325e72506cb3023911c870056265ef63b305fd5..1ca69665c4e446ce4023b90713a86376c91310ee 100644 (file)
@@ -324,24 +324,6 @@ _set_database_path (notmuch_database_t *notmuch,
     _notmuch_config_cache (notmuch, NOTMUCH_CONFIG_DATABASE_PATH, path);
 }
 
-static void
-_init_libs ()
-{
-
-    static int initialized = 0;
-
-    /* Initialize the GLib type system and threads */
-#if ! GLIB_CHECK_VERSION (2, 35, 1)
-    g_type_init ();
-#endif
-
-    /* Initialize gmime */
-    if (! initialized) {
-       g_mime_init ();
-       initialized = 1;
-    }
-}
-
 static void
 _load_database_state (notmuch_database_t *notmuch)
 {
@@ -515,7 +497,7 @@ notmuch_database_open_with_config (const char *database_path,
     GKeyFile *key_file = NULL;
     bool split = false;
 
-    _init_libs ();
+    _notmuch_init ();
 
     notmuch = _alloc_notmuch ();
     if (! notmuch) {
@@ -612,7 +594,7 @@ notmuch_database_create_with_config (const char *database_path,
     int err;
     bool split = false;
 
-    _init_libs ();
+    _notmuch_init ();
 
     notmuch = _alloc_notmuch ();
     if (! notmuch) {
@@ -808,7 +790,7 @@ notmuch_database_load_config (const char *database_path,
     GKeyFile *key_file = NULL;
     bool split = false;
 
-    _init_libs ();
+    _notmuch_init ();
 
     notmuch = _alloc_notmuch ();
     if (! notmuch) {
diff --git a/notmuch-client-init.c b/notmuch-client-init.c
new file mode 100644 (file)
index 0000000..60db6ba
--- /dev/null
@@ -0,0 +1,18 @@
+#include "notmuch-client.h"
+#include "gmime-filter-reply.h"
+
+/* Caller is responsible for only calling this once */
+
+void
+notmuch_client_init (void)
+{
+#if ! GLIB_CHECK_VERSION (2, 35, 1)
+    g_type_init ();
+#endif
+
+    g_mime_init ();
+
+    g_mime_filter_reply_module_init ();
+
+    talloc_enable_null_tracking ();
+}
index 270553ad7f1cc9d5f79c4a20226301fdb2f49871..8227fea479d4e234da32c4e2f9d26dfd4f60cf41 100644 (file)
@@ -250,6 +250,10 @@ json_quote_chararray (const void *ctx, const char *str, const size_t len);
 char *
 json_quote_str (const void *ctx, const char *str);
 
+/* notmuch-client-init.c */
+
+void notmuch_client_init (void);
+
 /* notmuch-config.c */
 
 typedef enum {
index d9390c4d81ea10ff7e82196a5d034025b4915250..3430a3d35e7fe06052065575f21220457547d070 100644 (file)
@@ -32,7 +32,7 @@ static const char toplevel_config_comment[] =
     "\n"
     " For more information about notmuch, see https://notmuchmail.org";
 
-struct config_group {
+static const struct config_group {
     const char *group_name;
     const char *comment;
 } group_comment_table [] = {
@@ -512,14 +512,14 @@ typedef struct config_key {
     bool (*validate)(const char *);
 } config_key_info_t;
 
-static struct config_key
+static const struct config_key
     config_key_table[] = {
     { "index.decrypt",   false,  NULL },
     { "index.header.",   true,   validate_field_name },
     { "query.",          true,   NULL },
 };
 
-static config_key_info_t *
+static const config_key_info_t *
 _config_key_info (const char *item)
 {
     for (size_t i = 0; i < ARRAY_SIZE (config_key_table); i++) {
@@ -583,7 +583,7 @@ notmuch_config_command_set (notmuch_database_t *notmuch,
                            int argc, char *argv[])
 {
     char *group, *key;
-    config_key_info_t *key_info;
+    const config_key_info_t *key_info;
     notmuch_conffile_t *config;
     bool update_database = false;
     int opt_index, ret;
index 00c0046873f50cc788717ebb86ef6a10314bf70a..e3d87e4aed184af827b35e0e5276ff9b6cdc3f4d 100644 (file)
@@ -34,7 +34,7 @@ static volatile sig_atomic_t interrupted;
 static void
 handle_sigint (unused (int sig))
 {
-    static char msg[] = "Stopping...         \n";
+    static const char msg[] = "Stopping...         \n";
 
     /* This write is "opportunistic", so it's okay to ignore the
      * result.  It is not required for correctness, and if it does
index 993359d603a9bf75d9e606014741ee9cc6f0d83f..1162e25a1273975c7a9c77473f5e6299e23fbc13 100644 (file)
@@ -81,7 +81,7 @@ static volatile sig_atomic_t interrupted;
 static void
 handle_sigint (unused (int sig))
 {
-    static char msg[] = "Stopping...         \n";
+    static const char msg[] = "Stopping...         \n";
 
     /* This write is "opportunistic", so it's okay to ignore the
      * result.  It is not required for correctness, and if it does
index 8904c1f41dca4d880a23708616705b76ede399eb..a7380a4bc197beb60f8140b9c37c5cc06ed8cf3e 100644 (file)
@@ -26,7 +26,7 @@ static volatile sig_atomic_t interrupted;
 static void
 handle_sigint (unused (int sig))
 {
-    static char msg[] = "Stopping...         \n";
+    static const char msg[] = "Stopping...         \n";
 
     /* This write is "opportunistic", so it's okay to ignore the
      * result.  It is not required for correctness, and if it does
index 667a75d6b960c3b2cc27b75d08753a813badc037..de428c8e9d99b902701a296a577cba87cb00c99c 100644 (file)
@@ -27,7 +27,7 @@ static volatile sig_atomic_t interrupted;
 static void
 handle_sigint (unused (int sig))
 {
-    static char msg[] = "Stopping...         \n";
+    static const char msg[] = "Stopping...         \n";
 
     /* This write is "opportunistic", so it's okay to ignore the
      * result.  It is not required for correctness, and if it does
index 2429999c2694345dd71b556e282b6dbb5a943dbe..d0a94fc2650993ae18bbd1ae6eae0109c3ca249b 100644 (file)
--- a/notmuch.c
+++ b/notmuch.c
@@ -139,7 +139,7 @@ notmuch_process_shared_indexing_options (notmuch_database_t *notmuch)
 }
 
 
-static command_t commands[] = {
+static const command_t commands[] = {
     { NULL, notmuch_command, NOTMUCH_COMMAND_CONFIG_CREATE | NOTMUCH_COMMAND_CONFIG_LOAD,
       "Notmuch main command." },
     { "setup", notmuch_setup_command, NOTMUCH_COMMAND_CONFIG_CREATE | NOTMUCH_COMMAND_CONFIG_LOAD,
@@ -189,7 +189,7 @@ typedef struct help_topic {
     const char *summary;
 } help_topic_t;
 
-static help_topic_t help_topics[] = {
+static const help_topic_t help_topics[] = {
     { "search-terms",
       "Common search term syntax." },
     { "hooks",
@@ -198,7 +198,7 @@ static help_topic_t help_topics[] = {
       "Message property conventions and documentation." },
 };
 
-static command_t *
+static const command_t *
 find_command (const char *name)
 {
     size_t i;
@@ -216,8 +216,8 @@ int notmuch_format_version;
 static void
 usage (FILE *out)
 {
-    command_t *command;
-    help_topic_t *topic;
+    const command_t *command;
+    const help_topic_t *topic;
     unsigned int i;
 
     fprintf (out,
@@ -308,8 +308,8 @@ exec_man (const char *page)
 static int
 _help_for (const char *topic_name)
 {
-    command_t *command;
-    help_topic_t *topic;
+    const command_t *command;
+    const help_topic_t *topic;
     unsigned int i;
 
     if (! topic_name) {
@@ -452,7 +452,7 @@ main (int argc, char *argv[])
     void *local;
     char *talloc_report;
     const char *command_name = NULL;
-    command_t *command;
+    const command_t *command;
     const char *config_file_name = NULL;
     notmuch_database_t *notmuch = NULL;
     int opt_index;
@@ -464,15 +464,10 @@ main (int argc, char *argv[])
        { }
     };
 
-    talloc_enable_null_tracking ();
+    notmuch_client_init ();
 
     local = talloc_new (NULL);
 
-    g_mime_init ();
-#if ! GLIB_CHECK_VERSION (2, 35, 1)
-    g_type_init ();
-#endif
-
     /* Globally default to the current output format version. */
     notmuch_format_version = NOTMUCH_FORMAT_CUR;
 
index fbc61028d2db4dfdc204cd4a78e2613cadd78c3c..59b37b1b8ff033092591ede74f9b1f7eb551ec62 100644 (file)
@@ -16,6 +16,7 @@ In addition to having notmuch, you need:
 - xz. Some speedup can be gotten by installing "pixz", but this is
   probably only worthwhile if you are debugging the tests.
 - valgrind (for the memory tests)
+- perf (optional, for more fine-grained timing)
 
 Getting set up to run tests:
 ----------------------------
@@ -56,11 +57,24 @@ supports the following arguments
 
 --small / --medium / --large   Choose corpus size.
 --debug                                Enable debugging. In particular don't delete
-                               temporary directories.
+                                temporary directories.
+--perf                          Run perf record in place of /usr/bin/time. Perf output can be
+                                found in a log directory.
+--call-graph {fp,lbr,dwarf}     Call graph option for perf record. Default is 'lbr'.
 
 When using the make targets, you can pass arguments to all test
 scripts by defining the make variable OPTIONS.
 
+Log Directory
+-------------
+
+The memory tests, and the time tests when option '--perf' is given
+save their output in a directory named as follows
+
+     log.$test_name-$corpus_size-$timestamp
+
+These directories are removed by "make clean".
+
 Writing tests
 -------------
 
index b70288ccaf316158b5c6ab16a46bff799c1b46a0..e7c502b6ca3d024aab87ab4d60d808fa8cf199df 100644 (file)
@@ -1,6 +1,9 @@
 . $(dirname "$0")/version.sh || exit 1
 
+debug=""
 corpus_size=large
+perf_callgraph=lbr
+use_perf=0
 
 while test "$#" -ne 0
 do
@@ -9,6 +12,15 @@ do
                debug=t;
                shift
                ;;
+       -p|--perf)
+               use_perf=1;
+               shift
+               ;;
+       -c|--call-graph)
+               shift
+               perf_callgraph=$1
+               shift
+               ;;
        -s|--small)
                corpus_size=small;
                shift
@@ -127,10 +139,20 @@ notmuch_new_with_cache ()
     fi
 }
 
+make_log_dir () {
+    local timestamp=$(date +%Y%m%dT%H%M%S)
+    log_dir=${TEST_DIRECTORY}/log.$(basename $0)-$corpus_size-${timestamp}
+    mkdir -p "${log_dir}"
+}
+
 time_start ()
 {
     add_email_corpus
 
+    if [[ "$use_perf" = 1 ]]; then
+       make_log_dir
+    fi
+
     print_header
 
     notmuch_new_with_cache time_run
@@ -140,9 +162,7 @@ memory_start ()
 {
     add_email_corpus
 
-    local timestamp=$(date +%Y%m%dT%H%M%S)
-    log_dir="${TEST_DIRECTORY}/log.$(basename $0)-$corpus_size-${timestamp}"
-    mkdir -p ${log_dir}
+    make_log_dir
 
     notmuch_new_with_cache memory_run
 }
@@ -193,7 +213,13 @@ time_run ()
     printf "  %-22s" "$1"
     test_count=$(($test_count+1))
     if test "$verbose" != "t"; then exec 4>test.output 3>&4; fi
-    if ! eval >&3 "/usr/bin/time -f '%e\t%U\t%S\t%M\t%I/%O' $2" ; then
+    if [[ "$use_perf" = 1 ]]; then
+       command_str="perf record --call-graph=${perf_callgraph} -o ${log_dir}/${test_count}.perf $2"
+    else
+       command_str="/usr/bin/time -f '%e\t%U\t%S\t%M\t%I/%O' $2"
+    fi
+
+    if ! eval >&3 "$command_str" ; then
        test_failure=$(($test_failure + 1))
        return 1
     fi
index e648924675f6551a33414d8d70b04e30b4ea1257..851ef64eaf5cf6d14328515708203d2349f8757e 100755 (executable)
@@ -5,6 +5,7 @@ test_description="emacs interface"
 
 EXPECTED=$NOTMUCH_SRCDIR/test/emacs.expected-output
 
+test_require_emacs
 add_email_corpus
 
 # syntax errors in test-lib.el cause mysterious failures
index 0aada4dfe7023a15384f121fb794f97126d9a30a..ae1d6a98bc9134ee74b49f6c9c344c7f53f04bbe 100755 (executable)
@@ -9,6 +9,7 @@ test_description='PGP/MIME signature verification and decryption'
 
 ##################################################
 
+test_require_emacs
 add_gnupg_home
 
 test_begin_subtest "emacs delivery of signed message"
index 8b2b52be032a34ec539ee673ffa8fee23dc8dc3d..12ac2525345a2196e6ce8f8ecc2036d3c15eeb7a 100755 (executable)
@@ -3,6 +3,7 @@
 test_description='S/MIME signature verification and decryption'
 . $(dirname "$0")/test-lib.sh || exit 1
 
+test_require_emacs
 test_require_external_prereq openssl
 test_require_external_prereq gpgsm
 
index 1ed5f28cfc455bd74d30f0f047032f75595c2886..b81bdfe192805f9d7a5ae2a1cd43af692405add8 100755 (executable)
@@ -7,6 +7,7 @@ test_description='indexing decrypted mail'
 
 ##################################################
 
+test_require_emacs
 add_gnupg_home
 
 # create a test encrypted message
index a0b76eb89ca1ba1da02c861a39f1e280105dbaf6..597330d3a1c2fbd92468afb3c98fae800ad814d1 100755 (executable)
@@ -8,95 +8,61 @@ fi
 
 add_email_corpus
 
+test_ruby() {
+    (
+       cat <<-EOF
+       require 'notmuch'
+       db = Notmuch::Database.new('$MAIL_DIR')
+       EOF
+       cat
+    ) | $NOTMUCH_RUBY -I "$NOTMUCH_BUILDDIR/bindings/ruby"> OUTPUT
+    test_expect_equal_file EXPECTED OUTPUT
+}
+
 test_begin_subtest "compare thread ids"
+notmuch search --sort=oldest-first --output=threads tag:inbox > EXPECTED
 test_ruby <<"EOF"
-require 'notmuch'
-$maildir = ENV['MAIL_DIR']
-if not $maildir then
-  abort('environment variable MAIL_DIR must be set')
-end
-@db = Notmuch::Database.new($maildir)
-@q = @db.query('tag:inbox')
-@q.sort = Notmuch::SORT_OLDEST_FIRST
-for t in @q.search_threads do
-  print t.thread_id, "\n"
+q = db.query('tag:inbox')
+q.sort = Notmuch::SORT_OLDEST_FIRST
+q.search_threads.each do |t|
+  puts 'thread:%s' % t.thread_id
 end
 EOF
-notmuch search --sort=oldest-first --output=threads tag:inbox | sed s/^thread:// > EXPECTED
-test_expect_equal_file EXPECTED OUTPUT
 
 test_begin_subtest "compare message ids"
+notmuch search --sort=oldest-first --output=messages tag:inbox > EXPECTED
 test_ruby <<"EOF"
-require 'notmuch'
-$maildir = ENV['MAIL_DIR']
-if not $maildir then
-  abort('environment variable MAIL_DIR must be set')
-end
-@db = Notmuch::Database.new($maildir)
-@q = @db.query('tag:inbox')
-@q.sort = Notmuch::SORT_OLDEST_FIRST
-for m in @q.search_messages do
-  print m.message_id, "\n"
+q = db.query('tag:inbox')
+q.sort = Notmuch::SORT_OLDEST_FIRST
+q.search_messages.each do |m|
+  puts 'id:%s' % m.message_id
 end
 EOF
-notmuch search --sort=oldest-first --output=messages tag:inbox | sed s/^id:// > EXPECTED
-test_expect_equal_file EXPECTED OUTPUT
 
 test_begin_subtest "get non-existent file"
+echo nil > EXPECTED
 test_ruby <<"EOF"
-require 'notmuch'
-$maildir = ENV['MAIL_DIR']
-if not $maildir then
-  abort('environment variable MAIL_DIR must be set')
-end
-@db = Notmuch::Database.new($maildir)
-result = @db.find_message_by_filename('i-dont-exist')
-print (result == nil)
+p db.find_message_by_filename('i-dont-exist')
 EOF
-test_expect_equal "$(cat OUTPUT)" "true"
 
 test_begin_subtest "count messages"
+notmuch count --output=messages tag:inbox > EXPECTED
 test_ruby <<"EOF"
-require 'notmuch'
-$maildir = ENV['MAIL_DIR']
-if not $maildir then
-  abort('environment variable MAIL_DIR must be set')
-end
-@db = Notmuch::Database.new($maildir)
-@q = @db.query('tag:inbox')
-print @q.count_messages(),"\n"
+puts db.query('tag:inbox').count_messages()
 EOF
-notmuch count --output=messages tag:inbox > EXPECTED
-test_expect_equal_file EXPECTED OUTPUT
 
 test_begin_subtest "count threads"
+notmuch count --output=threads tag:inbox > EXPECTED
 test_ruby <<"EOF"
-require 'notmuch'
-$maildir = ENV['MAIL_DIR']
-if not $maildir then
-  abort('environment variable MAIL_DIR must be set')
-end
-@db = Notmuch::Database.new($maildir)
-@q = @db.query('tag:inbox')
-print @q.count_threads(),"\n"
+puts db.query('tag:inbox').count_threads()
 EOF
-notmuch count --output=threads tag:inbox > EXPECTED
-test_expect_equal_file EXPECTED OUTPUT
 
 test_begin_subtest "get all tags"
+notmuch search --output=tags '*' > EXPECTED
 test_ruby <<"EOF"
-require 'notmuch'
-$maildir = ENV['MAIL_DIR']
-if not $maildir then
-  abort('environment variable MAIL_DIR must be set')
-end
-@db = Notmuch::Database.new($maildir)
-@t = @db.all_tags()
-for tag in @t do
-   print tag,"\n"
+db.all_tags.each do |tag|
+  puts tag
 end
 EOF
-notmuch search --output=tags '*' > EXPECTED
-test_expect_equal_file EXPECTED OUTPUT
 
 test_done
index cca56ca32cd6875e6da4dbcd7b3b90932b3e3bef..bd76d378e8fd693641ddd106a2299dde018dea1d 100755 (executable)
@@ -5,6 +5,7 @@ test_description="emacs notmuch-show view"
 
 EXPECTED=$NOTMUCH_SRCDIR/test/emacs-show.expected-output
 
+test_require_emacs
 add_email_corpus
 
 test_begin_subtest "Hiding Original Message region at beginning of a message"
index cb2c90b80991ec4a1bf31529bc1f6e74493eefdd..195485c156d312f46680792284ec62048faee828 100755 (executable)
@@ -5,6 +5,7 @@ test_description="emacs tree view interface"
 
 EXPECTED=$NOTMUCH_SRCDIR/test/emacs-tree.expected-output
 
+test_require_emacs
 add_email_corpus
 
 test_begin_subtest "Basic notmuch-tree view in emacs"
index 45e61568ec62540b03094562dfb3aa1c0def08f8..5d6ac9f052b15583407e9117fdb1a6d11b29ec94 100755 (executable)
@@ -3,6 +3,8 @@
 test_description="emacs forwarding"
 . $(dirname "$0")/test-lib.sh || exit 1
 
+test_require_emacs
+
 test_begin_subtest "Forward setting the correct references header"
 # Check that, when forwarding a message, the new message has
 # a References-header pointing to the original (forwarded) message.
index 4c9f2a2103e32a18c2c14dc257669300ecbe4d6f..d46bb4c34a9165599542b2eff981e5d224f63d67 100644 (file)
@@ -112,6 +112,13 @@ unset ALTERNATE_EDITOR
 
 # for reproducibility
 unset EMAIL
+unset NAME
+
+test_require_emacs () {
+    test_require_external_prereq emacs
+    test_require_external_prereq ${TEST_EMACSCLIENT}
+    test_require_external_prereq dtach
+}
 
 add_gnupg_home ()
 {
@@ -591,6 +598,9 @@ test_emacs_expect_t () {
                exec 1>&6 2>&7          # Restore stdout and stderr
                inside_subtest=
 
+               # test_emacs may update missing external prerequisites
+               test_check_missing_external_prereqs_ "$test_subtest_name" && return
+
                # Report success/failure.
                result=$(cat OUTPUT)
                if [ "$result" = t ]
@@ -708,10 +718,15 @@ import os, sys, pwd, socket
 pw = pwd.getpwuid(os.getuid())
 user = pw.pw_name
 name = pw.pw_gecos.partition(",")[0]
-fqdn = socket.getfqdn()
+fqdn = socket.getaddrinfo(socket.gethostname(), 0, 0, socket.SOCK_STREAM, 0, socket.AI_CANONNAME)[0][3]
 
 for l in sys.stdin:
-    l = l.replace(user, "USERNAME").replace(fqdn, "FQDN").replace(".(none)","").replace(name, "USER_FULL_NAME")
+    if user:
+        l = l.replace(user, "USERNAME")
+    if fqdn:
+        l = l.replace(fqdn, "FQDN").replace(".(none)","")
+    if name:
+        l = l.replace(name, "USER_FULL_NAME")
     sys.stdout.write(l)
 '
 }
@@ -913,7 +928,7 @@ test_expect_success () {
                test_run_ "$1"
                run_ret="$?"
                # test_run_ may update missing external prerequisites
-               test_check_missing_external_prereqs_ "$@" ||
+               test_check_missing_external_prereqs_ "$test_subtest_name" ||
                if [ "$run_ret" = 0 -a "$eval_ret" = 0 ]
                then
                        test_ok_
@@ -937,7 +952,7 @@ test_expect_code () {
                test_run_ "$2"
                run_ret="$?"
                # test_run_ may update missing external prerequisites,
-               test_check_missing_external_prereqs_ "$@" ||
+               test_check_missing_external_prereqs_ "$test_subtest_name" ||
                if [ "$run_ret" = 0 -a "$eval_ret" = "$1" ]
                then
                        test_ok_
@@ -1109,10 +1124,6 @@ test_python() {
        $NOTMUCH_PYTHON -B - > OUTPUT
 }
 
-test_ruby() {
-    MAIL_DIR=$MAIL_DIR $NOTMUCH_RUBY -I "$NOTMUCH_BUILDDIR/bindings/ruby"> OUTPUT
-}
-
 test_C () {
     local exec_file test_file
     exec_file="test${test_count}"
index 541698cdfee7939e05aa3554ff39c91295920940..c1c2f63d20178dab69f92c9ff9aab4631dda6ee5 100644 (file)
@@ -317,6 +317,9 @@ ruby << EOF
        $curbuf.render do |b|
                q = $curbuf.query(get_cur_view)
                q.sort = Notmuch::SORT_OLDEST_FIRST
+               $exclude_tags.each { |t|
+                       q.add_tag_exclude(t)
+               }
                msgs = q.search_messages
                msgs.each do |msg|
                        m = Mail.read(msg.filename)