reindex: drop notmuch_param_t, use notmuch_indexopts_t instead

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.
This commit is contained in:
Daniel Kahn Gillmor 2017-08-17 19:14:26 -04:00 committed by David Bremner
parent b10ce6bc23
commit eb232ee0ab
6 changed files with 66 additions and 7 deletions

View 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 = \

View 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;

33
lib/indexopts.c Normal file
View file

@ -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);
}

View 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;

View 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
*

View 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));