From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id EGIDK8jaQGBvbgAA0tVLHw (envelope-from ) for ; Thu, 04 Mar 2021 13:04:08 +0000 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id oGbDJsjaQGB1RgAAB5/wlQ (envelope-from ) for ; Thu, 04 Mar 2021 13:04:08 +0000 Received: from mail.notmuchmail.org (nmbug.tethera.net [IPv6:2607:5300:201:3100::1657]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id D7795221E3 for ; Thu, 4 Mar 2021 14:04:07 +0100 (CET) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 48B8B27C38; Thu, 4 Mar 2021 08:02:29 -0500 (EST) Received: from fethera.tethera.net (fethera.tethera.net [IPv6:2607:5300:60:c5::1]) by mail.notmuchmail.org (Postfix) with ESMTP id C3E1027564 for ; Thu, 4 Mar 2021 08:02:04 -0500 (EST) Received: by fethera.tethera.net (Postfix, from userid 1001) id 972E65FA96; Thu, 4 Mar 2021 08:02:04 -0500 (EST) Received: (nullmailer pid 4047185 invoked by uid 1000); Thu, 04 Mar 2021 13:01:45 -0000 From: David Bremner To: notmuch@notmuchmail.org Cc: David Bremner Subject: [PATCH 11/27] CLI/config: use merged config for "config get" Date: Thu, 4 Mar 2021 09:01:23 -0400 Message-Id: <20210304130139.4046183-12-david@tethera.net> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210304130139.4046183-1-david@tethera.net> References: <20210304130139.4046183-1-david@tethera.net> MIME-Version: 1.0 Message-ID-Hash: KSSXNCCJTYFO4TLECG66IZZQ4FMHBXI7 X-Message-ID-Hash: KSSXNCCJTYFO4TLECG66IZZQ4FMHBXI7 X-MailFrom: bremner@tethera.net 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-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1614863048; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=4FRVYH0Ew1L+Bhb5lgMJcdDhdx8fv5zRr7OOoOPc+dE=; b=plaBBOgO5gHC7rag182COHqj6LzCk0IipO9mjhRlVgQzEuulORru7nuHpzPA+eX5ITGP3p kWa9DhtlzKE6YfbRwBhGuogeti0VWRlK5/8r0lfmz62XaDfL1UBvizZF5xN+RByCpybepq ZSUnpNxCOc9FLQ6iyRMAXy9xat9E+3UA02aLfninM19PxStihmu5Ao+UBWwsVmdO8e32LT kHV0t0H//Kt9Rp6sxps2Wx3cl5pyHBvLKh7MpoXSgZiMjJHyLwxQtlQkM202q66s1gre8S wRTsx8MUHkCSJ5uPm7gubt+duO1lZtjTRsQmj16XNesemPoHzybPF3D6Rewqpw== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1614863048; a=rsa-sha256; cv=none; b=OzHzvuXLoDDC/00Prr3VCRpcRL8zkyhMFlqSLZXlapsw18jTNLEpprGZDuzscnSbCPi+JE qW0mHpZpvgt3VW6iDGUyb17EHaRwGCBzvwR4MGcZBP1p76A/PhlHA29uw6XuEswrk5ZIec YB8uLGo79WuRvfsUIJlzbacEHDzN4obMaD8vfyeMc7ODHaq05rduHq0KmhwyJXhAF2sc0I i8esoXECnnoMlcoAkTD8dnJGOhTpTbt2BnFyFTn+Hrte8IljrFzIU0JWVbkguyL7GBrBmH ImcwLGjHNiN0x/FmixhpAirAzED3Yk34WPXedbMI6L3Q2nF8/EPEsXN/SOy8Mw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 2607:5300:201:3100::1657 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Spam-Score: -0.80 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 2607:5300:201:3100::1657 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Queue-Id: D7795221E3 X-Spam-Score: -0.80 X-Migadu-Scanner: scn1.migadu.com X-TUID: faDYVgvI+NT5 This commit starts the conversion of notmuch-config.c functionality (as opposed to just interface) to the new config framework. The change to T030-config is because of the move of the canonicalization database paths from the notmuch_config_t accessor to the internal function _choose_database_path. --- notmuch-config.c | 92 +++++---------------------------------------- test/T030-config.sh | 31 ++++++++++++--- 2 files changed, 36 insertions(+), 87 deletions(-) diff --git a/notmuch-config.c b/notmuch-config.c index 0193401f..91b9eeaf 100644 --- a/notmuch-config.c +++ b/notmuch-config.c @@ -862,89 +862,17 @@ _config_key_info (const char *item) return NULL; } -static bool -_stored_in_db (const char *item) -{ - config_key_info_t *info; - - info = _config_key_info (item); - - return (info && info->in_db); -} - -static int -_print_db_config (notmuch_config_t *config, const char *name) -{ - notmuch_database_t *notmuch; - char *val; - - if (notmuch_database_open (notmuch_config_get_database_path (config), - NOTMUCH_DATABASE_MODE_READ_ONLY, ¬much)) - return EXIT_FAILURE; - - /* XXX Handle UUID mismatch? */ - - if (print_status_database ("notmuch config", notmuch, - notmuch_database_get_config (notmuch, name, &val))) - return EXIT_FAILURE; - - puts (val); - - return EXIT_SUCCESS; -} - static int -notmuch_config_command_get (notmuch_config_t *config, char *item) +notmuch_config_command_get (notmuch_database_t *notmuch, char *item) { - if (strcmp (item, "database.path") == 0) { - printf ("%s\n", notmuch_config_get_database_path (config)); - } else if (strcmp (item, "user.name") == 0) { - printf ("%s\n", notmuch_config_get_user_name (config)); - } else if (strcmp (item, "user.primary_email") == 0) { - printf ("%s\n", notmuch_config_get_user_primary_email (config)); - } else if (strcmp (item, "user.other_email") == 0) { - const char **other_email; - size_t i, length; - - other_email = notmuch_config_get_user_other_email (config, &length); - for (i = 0; i < length; i++) - printf ("%s\n", other_email[i]); - } else if (strcmp (item, "new.tags") == 0) { - const char **tags; - size_t i, length; - - tags = notmuch_config_get_new_tags (config, &length); - for (i = 0; i < length; i++) - printf ("%s\n", tags[i]); - } else if (STRNCMP_LITERAL (item, BUILT_WITH_PREFIX) == 0) { - printf ("%s\n", - notmuch_built_with (item + strlen (BUILT_WITH_PREFIX)) ? "true" : "false"); - } else if (_stored_in_db (item)) { - return _print_db_config (config, item); - } else { - char **value; - size_t i, length; - char *group, *key; - - if (_item_split (item, &group, &key)) - return 1; - - value = g_key_file_get_string_list (config->key_file, - group, key, - &length, NULL); - if (value == NULL) { - fprintf (stderr, "Unknown configuration item: %s.%s\n", - group, key); - return 1; - } - - for (i = 0; i < length; i++) - printf ("%s\n", value[i]); - - g_strfreev (value); + notmuch_config_values_t *list; + for (list = notmuch_config_get_values_string (notmuch, item); + notmuch_config_values_valid (list); + notmuch_config_values_move_to_next (list)) { + const char *val = notmuch_config_values_get (list); + puts(val); } - - return 0; + return EXIT_SUCCESS; } static int @@ -1105,7 +1033,7 @@ notmuch_config_command_list (notmuch_config_t *config) } int -notmuch_config_command (notmuch_config_t *config, unused(notmuch_database_t *notmuch), int argc, char *argv[]) +notmuch_config_command (notmuch_config_t *config, notmuch_database_t *notmuch, int argc, char *argv[]) { int ret; int opt_index; @@ -1133,7 +1061,7 @@ notmuch_config_command (notmuch_config_t *config, unused(notmuch_database_t *not "one argument.\n"); return EXIT_FAILURE; } - ret = notmuch_config_command_get (config, argv[1]); + ret = notmuch_config_command_get (notmuch, argv[1]); } else if (strcmp (argv[0], "set") == 0) { if (argc < 2) { fprintf (stderr, "Error: notmuch config set requires at least " diff --git a/test/T030-config.sh b/test/T030-config.sh index 67c9545c..8dff9c72 100755 --- a/test/T030-config.sh +++ b/test/T030-config.sh @@ -7,9 +7,12 @@ test_begin_subtest "Get string value" test_expect_equal "$(notmuch config get user.name)" "Notmuch Test Suite" test_begin_subtest "Get list value" -test_expect_equal "$(notmuch config get new.tags)" "\ +cat < EXPECTED +inbox unread -inbox" +EOF +notmuch config get new.tags | sort > OUTPUT +test_expect_equal_file EXPECTED OUTPUT test_begin_subtest "Set string value" notmuch config set foo.string "this is a string value" @@ -96,14 +99,32 @@ test_expect_equal "$(notmuch --config=alt-config-link config get user.name)" \ test_begin_subtest "Writing config file through symlink follows symlink" test_expect_equal "$(readlink alt-config-link)" "alt-config" +test_begin_subtest "Round trip arbitrary key" +key=g${RANDOM}.m${RANDOM} +value=${RANDOM} +notmuch config set ${key} ${value} +output=$(notmuch config get ${key}) +test_expect_equal "${output}" "${value}" + +test_begin_subtest "Clear arbitrary key" +notmuch config set ${key} +output=$(notmuch config get ${key}) +test_expect_equal "${output}" "" + +db_path=${HOME}/database-path + test_begin_subtest "Absolute database path returned" notmuch config set database.path ${HOME}/Maildir test_expect_equal "$(notmuch config get database.path)" \ "${HOME}/Maildir" -test_begin_subtest "Relative database path properly expanded" +ln -s `pwd`/mail home/Maildir +add_email_corpus +test_begin_subtest "Relative database path expanded in open" notmuch config set database.path Maildir -test_expect_equal "$(notmuch config get database.path)" \ - "${HOME}/Maildir" +path=$(notmuch config get database.path) +count=$(notmuch count '*') +test_expect_equal "${path} ${count}" \ + "Maildir 52" test_done -- 2.30.1