From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id 2J0uLuKtAF9JLwAA0tVLHw (envelope-from ) for ; Sat, 04 Jul 2020 16:27:14 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id 2BcJKuKtAF/mLAAA1q6Kng (envelope-from ) for ; Sat, 04 Jul 2020 16:27:14 +0000 Received: from mail.notmuchmail.org (nmbug.tethera.net [144.217.243.247]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 2D13A9404CB for ; Sat, 4 Jul 2020 16:27:12 +0000 (UTC) Received: from [144.217.243.247] (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id C1DD21FAE6; Sat, 4 Jul 2020 12:27:05 -0400 (EDT) Received: from mail-ed1-x543.google.com (mail-ed1-x543.google.com [IPv6:2a00:1450:4864:20::543]) by mail.notmuchmail.org (Postfix) with ESMTPS id D187A1F709 for ; Sat, 4 Jul 2020 12:27:03 -0400 (EDT) Received: by mail-ed1-x543.google.com with SMTP id z17so30545334edr.9 for ; Sat, 04 Jul 2020 09:27:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:in-reply-to:references:date:message-id :mime-version; bh=iPRPYru9fpkLOh+klq66lOt8mA+69Ld9ZPfkcBDRnVk=; b=j4ObOXMQqZfhfXQMyk+LEqVybQWH9OA4mN88wwtnQ1DvGNE2uGAFmMPJtHOcZ6pM3S j1GIk5/09qAsRnruGgnFFFM74BRbpg7c6LXIJxmkh1HNwgkRP0pL6/WfEOMVbkrOp1p+ 3dEO34e4NkcK43itvoBV1MwF0RLF+jJGtNtfpi3SJbU0iT2GoGwlSESO0G+g5djRFClN ovMWg4kEFpyW6MpN3+VwAL5+yPCBozjnNL5fZX8A9GZ3EOD3jkvuCrVczO5kFuernmww LWxZ/l4I5fpvOSzfLmNkK5oL9styyFTEJS7YUfRuEJ5Q3tD7KB1TcQctOOQqC4tpubhu i2PQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:in-reply-to:references :date:message-id:mime-version; bh=iPRPYru9fpkLOh+klq66lOt8mA+69Ld9ZPfkcBDRnVk=; b=CKQfGWmbFfvBB9GkA2FO/rmf2WG4EEfvXDgOw6FOHWGqr2D97DRX9SLjLBM3vXehSj g5toWpBGColKUKvGj669bUYwihchcn/63nZCJ6z8ldfoTmKUJLgIoVmbbDMzA/Fvvdd8 o8IATcApjo9+RruIvRmYNofLZfAyNJyayEr3SqyDuAq0O0Cc0FegsOZhTHAFuBg/yb8t BNICyj9H1iOmx9g7MVFFjsnJF4ofgXWOL7iND5EfRtD85ihCWOj5bR8QeRpncOOlAPs8 yfs42G595uiTOwFr9uoa/Y+UMHLqWkyl+/9IJYigj4ykRcY4iIXn5ktBvmMlnn0d4eih iCeA== X-Gm-Message-State: AOAM531JVSWxzMnDr4ldPxLUqSb5Lcdmiyzv2scN3+z35S8Thb9t5xOL HeH+JqUixl2vdcDtU18EUz3CPT0S X-Google-Smtp-Source: ABdhPJxuztjkw1c2myZCdE10kVy1BDI/l3+6goBopL1vUdCAWwC9lKXXrBay1Xi8IaWb/UABNezzSQ== X-Received: by 2002:a05:6402:176e:: with SMTP id da14mr31252608edb.262.1593880015548; Sat, 04 Jul 2020 09:26:55 -0700 (PDT) Received: from powell.devork.be (2a02-8388-8480-1180-4c18-fc69-8d8c-22b5.cable.dynamic.v6.surfer.at. [2a02:8388:8480:1180:4c18:fc69:8d8c:22b5]) by smtp.gmail.com with ESMTPSA id b14sm10978835ejg.18.2020.07.04.09.26.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 Jul 2020 09:26:54 -0700 (PDT) Sender: Floris Bruynooghe Received: (nullmailer pid 239443 invoked by uid 1000); Sat, 04 Jul 2020 16:26:53 -0000 From: Floris Bruynooghe To: David Bremner , notmuch@notmuchmail.org Cc: David Bremner Subject: Re: [RFC PATCH] lib: document new database_open API In-Reply-To: <20200703134338.3311659-1-david@tethera.net> References: <20200703134338.3311659-1-david@tethera.net> Date: Sat, 04 Jul 2020 18:26:53 +0200 Message-ID: <87eeprxn3m.fsf@powell.devork.be> MIME-Version: 1.0 Message-ID-Hash: 6R2INUYH3PYPMJHA5F6EBZBL6XK7F3VN X-Message-ID-Hash: 6R2INUYH3PYPMJHA5F6EBZBL6XK7F3VN X-MailFrom: floris.bruynooghe@gmail.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-notmuch.notmuchmail.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.1 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Scanner: scn0 Authentication-Results: aspmx1.migadu.com; dkim=fail (body hash did not verify) header.d=gmail.com header.s=20161025 header.b=j4ObOXMQ; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 144.217.243.247 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Spam-Score: 1.53 X-TUID: lHfe/Ew95h6e On Fri 03 Jul 2020 at 10:43 -0300, David Bremner wrote: > Several aspects of this are potentially controversial: > > 1) The use of environment variables as fallback. I understand the > discomfort with having a library function check the environment, but > this seems to be functionality people want, and it is better to > implement it once. > > 2) The use of both NULL and "" to do different things for config_path. > > 3) The new API is pretty complex, compared to the previous one. > --- > > There is not much code to back this so far. This is just me thinking > out loud at this point. The location calculation is done (and also > easy). The challenging part is probably updating > notmuch_database_get_config to do what this comment promises. > > I suspect database_create will probably need to be updated to match. > > Another question is if we should have an opaque set of options to pass > to open (in the style notmuch_indexopts_t). Currently this is just > future proofing as far as I know. > > lib/notmuch.h | 138 ++++++++++++++++++++++++++++++++++++++++---------- > 1 file changed, 111 insertions(+), 27 deletions(-) > > diff --git a/lib/notmuch.h b/lib/notmuch.h > index ceb5a018..6a46b80a 100644 > --- a/lib/notmuch.h > +++ b/lib/notmuch.h > @@ -301,52 +301,136 @@ typedef enum { > } notmuch_database_mode_t; > > /** > - * Open an existing notmuch database located at 'path'. > + * Deprecated alias for notmuch_database_open_with_config with > + * config_path=error_message=NULL > + * @deprecated Deprecated as of libnotmuch 5.2 (notmuch 0.31) > + */ > +NOTMUCH_DEPRECATED(5, 2) > +notmuch_status_t > +notmuch_database_open (const char *path, > + notmuch_database_mode_t mode, > + notmuch_database_t **database); > +/** > + * Deprecated alias for notmuch_database_open_with_config with > + * config_path=NULL > + * > + * @deprecated Deprecated as of libnotmuch 5.2 (notmuch 0.31) > + * > + */ > +NOTMUCH_DEPRECATED(5, 2) > +notmuch_status_t > +notmuch_database_open_verbose (const char *path, > + notmuch_database_mode_t mode, > + notmuch_database_t **database, > + char **error_message); > + > +/** > + * Open an existing notmuch database located at 'database_path', using > + * configuration in 'config_path'. > + * > + * @param[in] database_path > + * @parblock > + * Path to existing database. > + * > + * A notmuch database is a Xapian database containing appropriate > + * metadata. > * > * The database should have been created at some time in the past, > * (not necessarily by this process), by calling > - * notmuch_database_create with 'path'. By default the database should be > - * opened for reading only. In order to write to the database you need to > - * pass the NOTMUCH_DATABASE_MODE_READ_WRITE mode. > + * notmuch_database_create. > + * > + * If 'database_path' is NULL, use the location specified > + * > + * - in the environment variable NOTMUCH_DATABASE, if non-empty > + * > + * - by $XDG_DATA_HOME/notmuch/$NOTMUCH_PROFILE where XDG_DATA_HOME > + * defaults to "$HOME/.local/share" and NOTMUCH_PROFILE defaults to > + * "default" I like the profile support, is the plan for $XDG_DATA_HOME/notmuch/$NOTMUCH_PROFILE to be written when creating the database? > + * > + * If 'database_path' is non-NULL, but does not appear to be a Xapian > + * database, check for a directory '.notmuch/xapian' below > + * 'database_path'. > + * > + * @endparblock > + * @param[in] mode > + * @parblock > + * Mode to open database > + * > + * By default the database will be opened for reading only. In order > + * to write to the database you need to pass the > + * #NOTMUCH_DATABASE_MODE_READ_WRITE mode. > + * > + * @endparblock > + * @param[in] config_path > + * @parblock > + * Path to config file. > + * > + * Config file is key-value, with mandatory sections. See > + * notmuch-config(5) for more information. The key-value pair > + * overrides the corresponding configuration data stored in the > + * database (see notmuch_database_get_config) > * > - * An existing notmuch database can be identified by the presence of a > - * directory named ".notmuch" below 'path'. > + * If config_path is NULL use the path specified > + * > + * - in environment variable NOTMUCH_CONFIG, if non-empty > + * > + * - by XDG_CONFIG_HOME/notmuch/ where > + * XDG_CONFIG_HOME defaults to "$HOME/.config". > + * > + * - by $HOME/.notmuch-config > + * > + * If config_path is "" (empty string) then do not > + * open any configuration file. > + * @endparblock > + * @param[in] profile: > + * @parblock > + * Name of profile (configuration/database variant). > + * > + * If non-NULL, append to the directory / file path determined by > + * config_path. > + * > + * If NULL then use > + * - environment variable NOTMUCH_PROFILE if defined, > + * - otherwise "default" for directories and "" (empty string) for paths. > + * > + * @endparblock > + * @param[out] database > + * @parblock > + * Pointer to database object. May not be NULL. > * > * The caller should call notmuch_database_destroy when finished with > * this database. > * > * In case of any failure, this function returns an error status and > - * sets *database to NULL (after printing an error message on stderr). > + * sets *database to NULL. > * > - * Return value: > + * @endparblock > + * @param[out] error_message > + * If non-NULL, store error message from opening the database. > + * Any such message is allocated by \a malloc(3) and should be freed > + * by the caller. > * > - * NOTMUCH_STATUS_SUCCESS: Successfully opened the database. > + * @retval NOTMUCH_STATUS_SUCCESS: Successfully opened the database. > * > - * NOTMUCH_STATUS_NULL_POINTER: The given 'path' argument is NULL. > + * @retval NOTMUCH_STATUS_NULL_POINTER: The given \a database > + * argument is NULL. > * > - * NOTMUCH_STATUS_OUT_OF_MEMORY: Out of memory. > + * @retval NOTMUCH_STATUS_OUT_OF_MEMORY: Out of memory. > * > - * NOTMUCH_STATUS_FILE_ERROR: An error occurred trying to open the > - * database file (such as permission denied, or file not found, > + * @retval NOTMUCH_STATUS_FILE_ERROR: An error occurred trying to open the > + * database or config file (such as permission denied, or file not found, > * etc.), or the database version is unknown. > * > - * NOTMUCH_STATUS_XAPIAN_EXCEPTION: A Xapian exception occurred. > - */ > -notmuch_status_t > -notmuch_database_open (const char *path, > - notmuch_database_mode_t mode, > - notmuch_database_t **database); > -/** > - * Like notmuch_database_open, except optionally return an error > - * message. This message is allocated by malloc and should be freed by > - * the caller. > + * @retval NOTMUCH_STATUS_XAPIAN_EXCEPTION: A Xapian exception occurred. > */ > > notmuch_status_t > -notmuch_database_open_verbose (const char *path, > - notmuch_database_mode_t mode, > - notmuch_database_t **database, > - char **error_message); > +notmuch_database_open_with_config (const char *database_path, > + notmuch_database_mode_t mode, > + const char *config_path, > + const char *profile, > + notmuch_database_t **database, > + char **error_message); > > /** > * Retrieve last status string for given database. It's nice that the environment variable handling is done in the library, should make it more consistent for bindings. As long as it can be overwritten I guess. The API is rather complex though, perhaps easier when split across several functions? Maybe a notmuch_database_open_profile(const char *profile, notmuch_database_t**) is useful as the simple one which always does the right thing when called with NULL for profile. Not sure what other combinations would be needed.