--- /dev/null
+Return-Path: <tomi.ollila@iki.fi>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by arlo.cworth.org (Postfix) with ESMTP id 1C3186DE026C\r
+ for <notmuch@notmuchmail.org>; Sat, 7 May 2016 10:04:03 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at cworth.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0.601\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0.601 tagged_above=-999 required=5 tests=[AWL=-0.051,\r
+ SPF_NEUTRAL=0.652] autolearn=disabled\r
+Received: from arlo.cworth.org ([127.0.0.1])\r
+ by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id qr1U5KtbQ6OU for <notmuch@notmuchmail.org>;\r
+ Sat, 7 May 2016 10:03:54 -0700 (PDT)\r
+Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34])\r
+ by arlo.cworth.org (Postfix) with ESMTP id BA2E16DE00EB\r
+ for <notmuch@notmuchmail.org>; Sat, 7 May 2016 10:03:53 -0700 (PDT)\r
+Received: from guru.guru-group.fi (localhost [IPv6:::1])\r
+ by guru.guru-group.fi (Postfix) with ESMTP id A9CED100063;\r
+ Sat, 7 May 2016 20:03:51 +0300 (EEST)\r
+From: Tomi Ollila <tomi.ollila@iki.fi>\r
+To: David Bremner <david@tethera.net>, notmuch@notmuchmail.org\r
+Subject: Re: [Patch v3 05/11] lib: provide config API\r
+In-Reply-To: <1462065879-29860-6-git-send-email-david@tethera.net>\r
+References: <1462065879-29860-1-git-send-email-david@tethera.net>\r
+ <1462065879-29860-6-git-send-email-david@tethera.net>\r
+User-Agent: Notmuch/0.22+9~gb26b5ad (http://notmuchmail.org) Emacs/24.3.1\r
+ (x86_64-unknown-linux-gnu)\r
+X-Face: HhBM'cA~<r"^Xv\KRN0P{vn'Y"Kd;zg_y3S[4)KSN~s?O\"QPoL\r
+ $[Xv_BD:i/F$WiEWax}R(MPS`^UaptOGD`*/=@\1lKoVa9tnrg0TW?"r7aRtgk[F\r
+ !)g;OY^,BjTbr)Np:%c_o'jj,Z\r
+Date: Sat, 07 May 2016 20:03:51 +0300\r
+Message-ID: <m2zis1er60.fsf@guru.guru-group.fi>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=utf-8\r
+Content-Transfer-Encoding: quoted-printable\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.20\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <https://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch/>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <https://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Sat, 07 May 2016 17:04:03 -0000\r
+\r
+On Sun, May 01 2016, David Bremner <david@tethera.net> wrote:\r
+\r
+nits here\r
+\r
+> This is a thin wrapper around the Xapian metadata API. The job of this\r
+> layer is to keep the config key value pairs from colliding with other\r
+> metadata by transparently prefixing the keys, along with the usual glue\r
+> to provide a C interface.\r
+>\r
+> The split of _get_config into two functions is to allow returning of the\r
+> return value with different memory ownership semantics.\r
+> ---\r
+> lib/Makefile.local | 1 +\r
+> lib/config.cc | 90 ++++++++++++++++++++++++++++++++++++++++++++=\r
+++++++\r
+> lib/notmuch.h | 20 +++++++++++\r
+> test/T590-libconfig.sh | 58 ++++++++++++++++++++++++++++++++\r
+> 4 files changed, 169 insertions(+)\r
+> create mode 100644 lib/config.cc\r
+> create mode 100755 test/T590-libconfig.sh\r
+>\r
+> diff --git a/lib/Makefile.local b/lib/Makefile.local\r
+> index 36c3924..76b57cb 100644\r
+> --- a/lib/Makefile.local\r
+> +++ b/lib/Makefile.local\r
+> @@ -49,6 +49,7 @@ libnotmuch_cxx_srcs =3D \\r
+> $(dir)/index.cc \\r
+> $(dir)/message.cc \\r
+> $(dir)/query.cc \\r
+> + $(dir)/config.cc \\r
+> $(dir)/thread.cc\r
+>=20=20\r
+> libnotmuch_modules :=3D $(libnotmuch_c_srcs:.c=3D.o) $(libnotmuch_cxx_sr=\r
+cs:.cc=3D.o)\r
+> diff --git a/lib/config.cc b/lib/config.cc\r
+> new file mode 100644\r
+> index 0000000..af00d6f\r
+> --- /dev/null\r
+> +++ b/lib/config.cc\r
+> @@ -0,0 +1,90 @@\r
+> +/* metadata.cc - API for database metadata\r
+\r
+config.cc or metadata.cc -- decide ! ;D\r
+\r
+> + *\r
+> + * Copyright =C2=A9 2015 David Bremner\r
+\r
+this could be 2016 now (?) (like it matters)\r
+\r
+> + *\r
+> + * This program is free software: you can redistribute it and/or modify\r
+> + * it under the terms of the GNU General Public License as published by\r
+> + * the Free Software Foundation, either version 3 of the License, or\r
+> + * (at your option) any later version.\r
+> + *\r
+> + * This program is distributed in the hope that it will be useful,\r
+> + * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+> + * GNU General Public License for more details.\r
+> + *\r
+> + * You should have received a copy of the GNU General Public License\r
+> + * along with this program. If not, see http://www.gnu.org/licenses/ .\r
+> + *\r
+> + * Author: David Bremner <david@tethera.net>\r
+> + */\r
+> +\r
+> +#include "notmuch.h"\r
+> +#include "notmuch-private.h"\r
+> +#include "database-private.h"\r
+> +\r
+> +static const std::string CONFIG_PREFIX=3D"C";\r
+\r
+spacing. e.g. CONFIG_PREFIX =3D "C";\r
+\r
+> +\r
+> +notmuch_status_t\r
+> +notmuch_database_set_config (notmuch_database_t *notmuch,\r
+> + const char *key,\r
+> + const char *value)\r
+> +{\r
+> + notmuch_status_t status;\r
+> + Xapian::WritableDatabase *db;\r
+> +\r
+> + status =3D _notmuch_database_ensure_writable (notmuch);\r
+> + if (status)\r
+> + return status;\r
+> +\r
+> + try {\r
+> + db =3D static_cast <Xapian::WritableDatabase *> (notmuch->xapian_db);\r
+> + db->set_metadata (CONFIG_PREFIX+key, value);\r
+> + } catch (const Xapian::Error &error) {\r
+> + status =3D NOTMUCH_STATUS_XAPIAN_EXCEPTION;\r
+> + notmuch->exception_reported =3D TRUE;\r
+> + if (! notmuch->exception_reported) {\r
+> + _notmuch_database_log (notmuch, "Error: A Xapian exception occurred=\r
+ setting metadata: %s\n",\r
+\r
+The above goes up to column 104, but probably nothing is to be done there.\r
+\r
+> + error.get_msg().c_str());\r
+> + }\r
+> + }\r
+> + return NOTMUCH_STATUS_SUCCESS;\r
+> +}\r
+> +\r
+> +static notmuch_status_t\r
+> +_metadata_value (notmuch_database_t *notmuch,\r
+> + const char *key,\r
+> + std::string &value)\r
+> +{\r
+> + notmuch_status_t status =3D NOTMUCH_STATUS_SUCCESS;\r
+> +\r
+> + try {\r
+> + value =3D notmuch->xapian_db->get_metadata (CONFIG_PREFIX+key);\r
+\r
+spacing: e.g. (CONFIG_PREFIX + key);\r
+\r
+> + } catch (const Xapian::Error &error) {\r
+> + status =3D NOTMUCH_STATUS_XAPIAN_EXCEPTION;\r
+> + notmuch->exception_reported =3D TRUE;\r
+> + if (! notmuch->exception_reported) {\r
+> + _notmuch_database_log (notmuch, "Error: A Xapian exception occurred=\r
+ getting metadata: %s\n",\r
+> + error.get_msg().c_str());\r
+> + }\r
+> + }\r
+> + return status;\r
+> +}\r
+> +\r
+> +notmuch_status_t\r
+> +notmuch_database_get_config (notmuch_database_t *notmuch,\r
+> + const char *key,\r
+> + char **value) {\r
+\r
+In functions IIRC we always have opening brace in its own line.\r
+\r
+> + std::string strval;\r
+> + notmuch_status_t status;\r
+> +\r
+> + if (!value)\r
+> + return NOTMUCH_STATUS_NULL_POINTER;\r
+> +\r
+> + status =3D _metadata_value (notmuch, key, strval);\r
+> + if (status)\r
+> + return status;\r
+> +\r
+> + *value =3D strdup (strval.c_str ());\r
+> +\r
+> + return NOTMUCH_STATUS_SUCCESS;\r
+> +}\r
+\r
+Tomi\r