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 A8F7C6DE10A4 for ; Sat, 2 Mar 2019 07:42:07 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: -0.009 X-Spam-Level: X-Spam-Status: No, score=-0.009 tagged_above=-999 required=5 tests=[AWL=-0.008, SPF_PASS=-0.001] 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 YQ6Vra6Rc0gD for ; Sat, 2 Mar 2019 07:42:07 -0800 (PST) Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197]) by arlo.cworth.org (Postfix) with ESMTPS id 67D9E6DE10C2 for ; Sat, 2 Mar 2019 07:41:48 -0800 (PST) Received: from remotemail by fethera.tethera.net with local (Exim 4.89) (envelope-from ) id 1h06ln-0004K2-8K; Sat, 02 Mar 2019 10:41:47 -0500 Received: (nullmailer pid 25722 invoked by uid 1000); Sat, 02 Mar 2019 15:41:37 -0000 From: David Bremner To: notmuch@notmuchmail.org Subject: [PATCH 1/7] cli/config: refactor _stored_in_db Date: Sat, 2 Mar 2019 11:41:27 -0400 Message-Id: <20190302154133.25642-2-david@tethera.net> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190302154133.25642-1-david@tethera.net> References: <20190302154133.25642-1-david@tethera.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.29 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, 02 Mar 2019 15:42:07 -0000 This will make it easier to add other prefixes that are stored in the database, compared to special casing each one as "query." was. --- notmuch-config.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/notmuch-config.c b/notmuch-config.c index bf77cc9d..1517d0ff 100644 --- a/notmuch-config.c +++ b/notmuch-config.c @@ -821,17 +821,26 @@ _item_split (char *item, char **group, char **key) #define BUILT_WITH_PREFIX "built_with." +struct config_key { + const char *name; + bool prefix; +}; + static bool _stored_in_db (const char *item) { - const char * db_configs[] = { - "index.decrypt", + struct config_key db_configs[] = { + {"index.decrypt", false}, + {"query.", true}, }; - if (STRNCMP_LITERAL (item, "query.") == 0) - return true; - for (size_t i = 0; i < ARRAY_SIZE (db_configs); i++) - if (strcmp (item, db_configs[i]) == 0) + for (size_t i = 0; i < ARRAY_SIZE (db_configs); i++) { + if (db_configs[i].prefix && + strncmp (item, db_configs[i].name, + strlen(db_configs[i].name)) == 0) return true; + if (strcmp (item, db_configs[i].name) == 0) + return true; + } return false; } -- 2.20.1