From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:8:6d80::]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id PGC0JE8RbWCcIAEAgWs5BA (envelope-from ) for ; Wed, 07 Apr 2021 03:56:31 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id iGimHU8RbWBrSQAAbx9fmQ (envelope-from ) for ; Wed, 07 Apr 2021 01:56:31 +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)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 2DE8C1473D for ; Wed, 7 Apr 2021 03:56:31 +0200 (CEST) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 156EB29051; Tue, 6 Apr 2021 21:55:56 -0400 (EDT) Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197]) by mail.notmuchmail.org (Postfix) with ESMTP id 83C7E26A0A for ; Tue, 6 Apr 2021 21:55:42 -0400 (EDT) Received: by fethera.tethera.net (Postfix, from userid 1001) id 77F8F5FA96; Tue, 6 Apr 2021 21:55:42 -0400 (EDT) Received: (nullmailer pid 2964230 invoked by uid 1000); Wed, 07 Apr 2021 01:55:35 -0000 From: David Bremner To: notmuch@notmuchmail.org Cc: David Bremner Subject: [PATCH 12/28] CLI/config: use merged config for "config get" Date: Tue, 6 Apr 2021 22:55:14 -0300 Message-Id: <20210407015530.2964017-13-david@tethera.net> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210407015530.2964017-1-david@tethera.net> References: <20210407015530.2964017-1-david@tethera.net> MIME-Version: 1.0 Message-ID-Hash: PZ2AEGK6DKXXRND7PCPOHQCOF7N7MAJ6 X-Message-ID-Hash: PZ2AEGK6DKXXRND7PCPOHQCOF7N7MAJ6 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=1617760591; 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=fQgLn6tP1zNyLC9uXG7DivyxxikucpDbKokeFkOzay8=; b=iYBqLLUOvYD+O+rPVt/VdmZLg16rh6Pou6ZGDE1/8IjRWCkivjjexMIuDT3/x3Y3aGYMqr ztPEvZztLDWK7vB0KVa02W5NU1vfU5hd1lRV6bkwrnTpqadhxCT1DJhAnIYXtxrOJHLC1I BHmQsWhfNoeZLo1yT+DZQLWlWSOKh1K5WttIHywffmC7nMd937Qo12bk2w/gZqhMOS/3eu kW2KO7UgPg4cKEn1d6vq/8/RDgoLcL3J9e1fsxNBgEXyj/KSPak6nzYdm2B6Kpt4O5OmAu TmBqOygYTxvkDH39RF7Le7Ulx5u7Q0oj0MT359cXYMjFI65Md5gqwlguSTrN9A== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1617760591; a=rsa-sha256; cv=none; b=XGqIIY1tpN5OnUq4i/FG+R3Ob3sd/IQLedhHe+2bfkLRdyIp9r+B9vupaImvhKKOig67hh Dm/BTyWE0MAqiFKfl8v6sIix3S1kG9WFsOnLzSjg7vurCuyPu3CDYPYNP3FnRn8zHlyHI8 oH2i94TeF2/ULoAdZHOZKqcdQDNmLOuvOOdc1j0WLdCnZeYHOdDj+AycZauhD0GQHCAGli l/+DBQnrj0hypYBNlfRXkOY33IrVfyyCRlMLpegDfwycqssXe+nJHE8rDB25Sh8mzFtQBj sUlutpCm+hqm2Ws8DcRSV+ZmmfXrkoocwqFg7L797vfX+RnhKq2xhUvCx7zZQQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=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.02 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: 2DE8C1473D X-Spam-Score: 0.02 X-Migadu-Scanner: scn0.migadu.com X-TUID: c/aPzEHsfZZQ 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 | 91 +++++---------------------------------------- test/T030-config.sh | 31 ++++++++++++--- 2 files changed, 36 insertions(+), 86 deletions(-) diff --git a/notmuch-config.c b/notmuch-config.c index e1a583e6..50008f78 100644 --- a/notmuch-config.c +++ b/notmuch-config.c @@ -864,89 +864,18 @@ _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_config_command_get (notmuch_database_t *notmuch, char *item) { - 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); + notmuch_config_values_t *list; - return EXIT_SUCCESS; -} - -static int -notmuch_config_command_get (notmuch_config_t *config, 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); + 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 @@ -1107,7 +1036,7 @@ notmuch_config_command_list (notmuch_config_t *config) } int -notmuch_config_command (notmuch_config_t *config, unused(notmuch_database_t *notmuch), +notmuch_config_command (notmuch_config_t *config, notmuch_database_t *notmuch, int argc, char *argv[]) { int ret; @@ -1136,7 +1065,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 6610bf8e..ba29cbac 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.2