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 272C06DE00D4 for ; Fri, 20 Oct 2017 19:26:04 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: -0.022 X-Spam-Level: X-Spam-Status: No, score=-0.022 tagged_above=-999 required=5 tests=[AWL=-0.022] 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 ybcXanFA6brK for ; Fri, 20 Oct 2017 19:26:03 -0700 (PDT) Received: from che.mayfirst.org (che.mayfirst.org [162.247.75.118]) by arlo.cworth.org (Postfix) with ESMTP id 101D96DE0ACB for ; Fri, 20 Oct 2017 19:26:00 -0700 (PDT) Received: from fifthhorseman.net (ool-6c3a0662.static.optonline.net [108.58.6.98]) by che.mayfirst.org (Postfix) with ESMTPSA id 39244F9A2 for ; Fri, 20 Oct 2017 22:25:59 -0400 (EDT) Received: by fifthhorseman.net (Postfix, from userid 1000) id 4140F20F82; Fri, 20 Oct 2017 22:25:54 -0400 (EDT) From: Daniel Kahn Gillmor To: Notmuch Mail Subject: [PATCH 05/12] config: test whether an item is stored in the database by name Date: Fri, 20 Oct 2017 22:25:42 -0400 Message-Id: <20171021022549.2724-6-dkg@fifthhorseman.net> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20171021022549.2724-1-dkg@fifthhorseman.net> References: <20171021022549.2724-1-dkg@fifthhorseman.net> 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: Sat, 21 Oct 2017 02:26:04 -0000 QUERY_STRING was only used in two places, both to test whether a variable should be stored in (or retrieved from) the database. Since other configuration variables might be stored in the database in the future, consolidate that test into a single function. We also document that these configuration options should not be placed in the config file. --- doc/man1/notmuch-config.rst | 7 ++++++- notmuch-config.c | 13 ++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/doc/man1/notmuch-config.rst b/doc/man1/notmuch-config.rst index 71294554..539199c2 100644 --- a/doc/man1/notmuch-config.rst +++ b/doc/man1/notmuch-config.rst @@ -15,7 +15,11 @@ DESCRIPTION =========== The **config** command can be used to get or set settings in the notmuch -configuration file. +configuration file and corresponding database. + +Items marked **[STORED IN DATABASE]** are only in the database. They +should not be placed in the configuration file, and should be accessed +programmatically as described in the SYNOPSIS above. **get** The value of the specified configuration item is printed to @@ -142,6 +146,7 @@ The available configuration items are described below. **query.** + **[STORED IN DATABASE]** Expansion for named query called . See **notmuch-search-terms(7)** for more information about named queries. diff --git a/notmuch-config.c b/notmuch-config.c index 8fb59f96..74668718 100644 --- a/notmuch-config.c +++ b/notmuch-config.c @@ -808,7 +808,14 @@ _item_split (char *item, char **group, char **key) } #define BUILT_WITH_PREFIX "built_with." -#define QUERY_PREFIX "query." + +static bool +_stored_in_db (const char *item) +{ + if (STRNCMP_LITERAL (item, "query.") == 0) + return true; + return false; +} static int _print_db_config(notmuch_config_t *config, const char *name) @@ -857,7 +864,7 @@ notmuch_config_command_get (notmuch_config_t *config, char *item) } else if (STRNCMP_LITERAL (item, BUILT_WITH_PREFIX) == 0) { printf ("%s\n", notmuch_built_with (item + strlen (BUILT_WITH_PREFIX)) ? "true" : "false"); - } else if (STRNCMP_LITERAL (item, QUERY_PREFIX) == 0) { + } else if (_stored_in_db (item)) { return _print_db_config (config, item); } else { char **value; @@ -928,7 +935,7 @@ notmuch_config_command_set (notmuch_config_t *config, char *item, int argc, char return 1; } - if (STRNCMP_LITERAL (item, QUERY_PREFIX) == 0) { + if (_stored_in_db (item)) { return _set_db_config (config, item, argc, argv); } -- 2.14.2