From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by arlo.cworth.org (Postfix) with ESMTP id 04D476DE00DB for ; Tue, 8 Aug 2017 22:47:40 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: -0.06 X-Spam-Level: X-Spam-Status: No, score=-0.06 tagged_above=-999 required=5 tests=[AWL=-0.060] autolearn=disabled Received: from arlo.cworth.org ([127.0.0.1]) by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 29WjhVK5FixA for ; Tue, 8 Aug 2017 22:47:38 -0700 (PDT) Received: from che.mayfirst.org (che.mayfirst.org [162.247.75.118]) by arlo.cworth.org (Postfix) with ESMTP id D36D36DE00B4 for ; Tue, 8 Aug 2017 22:47:37 -0700 (PDT) Received: from fifthhorseman.net (ool-6c3a0662.static.optonline.net [108.58.6.98]) by che.mayfirst.org (Postfix) with ESMTPSA id 07B6CF99B for ; Wed, 9 Aug 2017 01:47:35 -0400 (EDT) Received: by fifthhorseman.net (Postfix, from userid 1000) id 1990A20A35; Wed, 9 Aug 2017 01:47:31 -0400 (EDT) From: Daniel Kahn Gillmor To: Notmuch Mail Subject: [PATCH 3/3] reindex: drop notmuch_param_t, use notmuch_indexopts_t instead Date: Wed, 9 Aug 2017 01:47:31 -0400 Message-Id: <20170809054731.23890-3-dkg@fifthhorseman.net> X-Mailer: git-send-email 2.13.2 In-Reply-To: <20170809054731.23890-1-dkg@fifthhorseman.net> References: <20170809054731.23890-1-dkg@fifthhorseman.net> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 09 Aug 2017 05:47:40 -0000 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 | 1 + lib/add-message.cc | 2 +- lib/indexopts.c | 33 +++++++++++++++++++++++++++++++++ lib/message.cc | 2 +- lib/notmuch-private.h | 1 - lib/notmuch.h | 31 ++++++++++++++++++++++++++++--- notmuch-reindex.c | 4 ++-- 7 files changed, 66 insertions(+), 8 deletions(-) create mode 100644 lib/indexopts.c diff --git a/lib/Makefile.local b/lib/Makefile.local index 0b5c4b08..93b08d15 100644 --- a/lib/Makefile.local +++ b/lib/Makefile.local @@ -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 = \ diff --git a/lib/add-message.cc b/lib/add-message.cc index 4454b2b0..85505ec4 100644 --- a/lib/add-message.cc +++ b/lib/add-message.cc @@ -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 index 00000000..2f9b841b --- /dev/null +++ b/lib/indexopts.c @@ -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 + */ + +#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); +} diff --git a/lib/message.cc b/lib/message.cc index 539d3320..98a88d3a 100644 --- a/lib/message.cc +++ b/lib/message.cc @@ -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; diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h index f6a497b5..b187a80f 100644 --- a/lib/notmuch-private.h +++ b/lib/notmuch-private.h @@ -632,7 +632,6 @@ _notmuch_thread_create (void *ctx, notmuch_exclude_t omit_exclude, notmuch_sort_t sort); - NOTMUCH_END_DECLS #ifdef __cplusplus diff --git a/lib/notmuch.h b/lib/notmuch.h index ed405dc5..7b06cd12 100644 --- a/lib/notmuch.h +++ b/lib/notmuch.h @@ -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__ */ /** @@ -601,7 +601,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); /** @@ -1428,7 +1428,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. @@ -2170,6 +2170,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 * diff --git a/notmuch-reindex.c b/notmuch-reindex.c index 44223042..bceac722 100644 --- a/notmuch-reindex.c +++ b/notmuch-reindex.c @@ -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)); -- 2.13.2