]> git.notmuchmail.org Git - notmuch/commitdiff
reindex: drop notmuch_param_t, use notmuch_indexopts_t instead
authorDaniel Kahn Gillmor <dkg@fifthhorseman.net>
Thu, 17 Aug 2017 23:14:26 +0000 (19:14 -0400)
committerDavid Bremner <david@tethera.net>
Wed, 23 Aug 2017 10:55:12 +0000 (07:55 -0300)
There are at least three places in notmuch that can trigger an
indexing action:

 * notmuch new
 * notmuch insert
 * notmuch reindex

I have plans to add some indexing options (e.g. indexing the cleartext
of encrypted parts, external filters, automated property injection)
that should properly be available in all places where indexing
happens.

I also want those indexing options to be exposed by (and constrained
by) the libnotmuch C API.

This isn't yet an API break because we've never made a release with
notmuch_param_t.

These indexing options are relevant in the listed places (and in the
libnotmuch analogues), but they aren't relevant in the other kinds of
functionality that notmuch offers (e.g. dump/restore, tagging, search,
show, reply).

So i think a generic "param" object isn't well-suited for this case.
In particular:

 * a param object sounds like it could contain parameters for some
   other (non-indexing) operation.  This sounds confusing -- why would
   i pass non-indexing parameters to a function that only does
   indexing?

 * bremner suggests online a generic param object would actually be
   passed as a list of param objects, argv-style.  In this case (at
   least in the obvious argv implementation), the params might be some
   sort of generic string.  This introduces a problem where the API of
   the library doesn't grow as new options are added, which means that
   when code outside the library tries to use a feature, it first has
   to test for it, and have code to handle it not being available.
   The indexopts approach proposed here instead makes it clear at
   compile time and at dynamic link time that there is an explicit
   dependency on that feature, which allows automated tools to keep
   track of what's needed and keeps the actual code simple.

My proposal adds the notmuch_indexopts_t as an opaque struct, so that
we can extend the list of options without causing ABI breakage.

The cost of this proposal appears to be that the "boilerplate" API
increases a little bit, with a generic constructor and destructor
function for the indexopts struct.

More patches will follow that make use of this indexopts approach.

lib/Makefile.local
lib/add-message.cc
lib/indexopts.c [new file with mode: 0644]
lib/message.cc
lib/notmuch.h
notmuch-reindex.c

index 0b5c4b0805f570ec27b62c4ada80c7a25ea5719e..93b08d1500675f62ac0ba74099339d1ab777a2f7 100644 (file)
@@ -43,6 +43,7 @@ libnotmuch_c_srcs =           \
        $(dir)/sha1.c           \
        $(dir)/built-with.c     \
        $(dir)/string-map.c     \
+       $(dir)/indexopts.c      \
        $(dir)/tags.c
 
 libnotmuch_cxx_srcs =          \
index 7b5cb70223d433339ed9519593ec6b277b8338d9..73bde7faf049601e90e0a7af91de806fcc009a7d 100644 (file)
@@ -460,7 +460,7 @@ _notmuch_database_link_message (notmuch_database_t *notmuch,
 notmuch_status_t
 notmuch_database_index_file (notmuch_database_t *notmuch,
                             const char *filename,
-                            notmuch_param_t unused (*indexopts),
+                            notmuch_indexopts_t unused (*indexopts),
                             notmuch_message_t **message_ret)
 {
     notmuch_message_file_t *message_file;
diff --git a/lib/indexopts.c b/lib/indexopts.c
new file mode 100644 (file)
index 0000000..2f9b841
--- /dev/null
@@ -0,0 +1,33 @@
+/* indexopts.c - options for indexing messages (currently a stub)
+ *
+ * Copyright © 2017 Daniel Kahn Gillmor
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see https://www.gnu.org/licenses/ .
+ *
+ * Author: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
+ */
+
+#include "notmuch-private.h"
+
+notmuch_indexopts_t *
+notmuch_database_get_default_indexopts (notmuch_database_t unused (*db))
+{
+    return NULL;
+}
+
+void
+notmuch_indexopts_destroy (notmuch_indexopts_t *indexopts)
+{
+    talloc_free (indexopts);
+}
index 539d3320b24144b093db6332785fe23e2218a6d2..98a88d3a4e34cde003844a2e5df16028d1c68fd9 100644 (file)
@@ -1939,7 +1939,7 @@ _notmuch_message_frozen (notmuch_message_t *message)
 
 notmuch_status_t
 notmuch_message_reindex (notmuch_message_t *message,
-                        notmuch_param_t unused (*indexopts))
+                        notmuch_indexopts_t unused (*indexopts))
 {
     notmuch_database_t *notmuch = NULL;
     notmuch_status_t ret = NOTMUCH_STATUS_SUCCESS;
index a64efc17ae367c370b9e0ecabaabde11f8b38ef2..e025bc1fb455a6f4fe2c53ea60908a4e5d489a71 100644 (file)
@@ -219,7 +219,7 @@ typedef struct _notmuch_tags notmuch_tags_t;
 typedef struct _notmuch_directory notmuch_directory_t;
 typedef struct _notmuch_filenames notmuch_filenames_t;
 typedef struct _notmuch_config_list notmuch_config_list_t;
-typedef struct _notmuch_param notmuch_param_t;
+typedef struct _notmuch_indexopts notmuch_indexopts_t;
 #endif /* __DOXYGEN__ */
 
 /**
@@ -603,7 +603,7 @@ notmuch_database_get_directory (notmuch_database_t *database,
 notmuch_status_t
 notmuch_database_index_file (notmuch_database_t *database,
                             const char *filename,
-                            notmuch_param_t *indexopts,
+                            notmuch_indexopts_t *indexopts,
                             notmuch_message_t **message);
 
 /**
@@ -1430,7 +1430,7 @@ notmuch_message_get_filenames (notmuch_message_t *message);
  */
 notmuch_status_t
 notmuch_message_reindex (notmuch_message_t *message,
-                        notmuch_param_t *indexopts);
+                        notmuch_indexopts_t *indexopts);
 
 /**
  * Message flags.
@@ -2172,6 +2172,31 @@ notmuch_config_list_move_to_next (notmuch_config_list_t *config_list);
 void
 notmuch_config_list_destroy (notmuch_config_list_t *config_list);
 
+
+/**
+ * get the current default indexing options for a given database.
+ *
+ * This object will survive until the database itself is destroyed,
+ * but the caller may also release it earlier with
+ * notmuch_indexopts_destroy.
+ *
+ * This object represents a set of options on how a message can be
+ * added to the index.  At the moment it is a featureless stub.
+ *
+ * @since libnotmuch 5.1 (notmuch 0.26)
+ */
+notmuch_indexopts_t *
+notmuch_database_get_default_indexopts (notmuch_database_t *db);
+
+/**
+ * Destroy a notmuch_indexopts_t object.
+ *
+ * @since libnotmuch 5.1 (notmuch 0.26)
+ */
+void
+notmuch_indexopts_destroy (notmuch_indexopts_t *options);
+
+
 /**
  * interrogate the library for compile time features
  *
index 44223042f46c1dc8536726f3c64d8448a2694f30..bceac72284649b7c2605e952f40fd53dff37af52 100644 (file)
@@ -40,7 +40,7 @@ handle_sigint (unused (int sig))
  */
 static int
 reindex_query (notmuch_database_t *notmuch, const char *query_string,
-              notmuch_param_t *indexopts)
+              notmuch_indexopts_t *indexopts)
 {
     notmuch_query_t *query;
     notmuch_messages_t *messages;
@@ -89,7 +89,7 @@ notmuch_reindex_command (notmuch_config_t *config, int argc, char *argv[])
     struct sigaction action;
     int opt_index;
     int ret;
-    notmuch_param_t *indexopts = NULL;
+    notmuch_indexopts_t *indexopts = NULL;
 
     /* Set up our handler for SIGINT */
     memset (&action, 0, sizeof (struct sigaction));