Re: [PATCH v3 4/5] config: Add 'config list' command
authorJameson Graef Rollins <jrollins@finestructure.net>
Tue, 10 Apr 2012 07:22:01 +0000 (00:22 +1700)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:46:12 +0000 (09:46 -0800)
aa/42b175784a514f404f15eb243d16b15e8c17cc [new file with mode: 0644]

diff --git a/aa/42b175784a514f404f15eb243d16b15e8c17cc b/aa/42b175784a514f404f15eb243d16b15e8c17cc
new file mode 100644 (file)
index 0000000..5da2c29
--- /dev/null
@@ -0,0 +1,189 @@
+Return-Path: <jrollins@finestructure.net>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id 92984431FAF\r
+       for <notmuch@notmuchmail.org>; Tue, 10 Apr 2012 00:22:11 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -2.29\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-2.29 tagged_above=-999 required=5\r
+       tests=[RCVD_IN_DNSWL_MED=-2.3, T_MIME_NO_TEXT=0.01] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id zO5Msrzt36o3 for <notmuch@notmuchmail.org>;\r
+       Tue, 10 Apr 2012 00:22:11 -0700 (PDT)\r
+Received: from outgoing-mail.its.caltech.edu (outgoing-mail.its.caltech.edu\r
+       [131.215.239.19])\r
+       by olra.theworths.org (Postfix) with ESMTP id 0346F431FAE\r
+       for <notmuch@notmuchmail.org>; Tue, 10 Apr 2012 00:22:10 -0700 (PDT)\r
+Received: from fire-doxen.imss.caltech.edu (localhost [127.0.0.1])\r
+       by fire-doxen-postvirus (Postfix) with ESMTP id 6A9EB2E50D7C;\r
+       Tue, 10 Apr 2012 00:22:10 -0700 (PDT)\r
+X-Spam-Scanned: at Caltech-IMSS on fire-doxen by amavisd-new\r
+Received: from finestructure.net (unknown [76.89.193.65])\r
+       (Authenticated sender: jrollins)\r
+       by fire-doxen-submit (Postfix) with ESMTP id 7EA282E50D42;\r
+       Tue, 10 Apr 2012 00:22:07 -0700 (PDT)\r
+Received: by finestructure.net (Postfix, from userid 1000)\r
+       id 1732D762; Tue, 10 Apr 2012 00:22:07 -0700 (PDT)\r
+From: Jameson Graef Rollins <jrollins@finestructure.net>\r
+To: Peter Wang <novalazy@gmail.com>, notmuch@notmuchmail.org\r
+Subject: Re: [PATCH v3 4/5] config: Add 'config list' command\r
+In-Reply-To: <1333676886-9835-5-git-send-email-novalazy@gmail.com>\r
+References: <1332282698-7951-1-git-send-email-novalazy@gmail.com>\r
+       <1333676886-9835-1-git-send-email-novalazy@gmail.com>\r
+       <1333676886-9835-5-git-send-email-novalazy@gmail.com>\r
+User-Agent: Notmuch/0.12+108~g7bdb40c (http://notmuchmail.org) Emacs/23.4.1\r
+       (x86_64-pc-linux-gnu)\r
+Date: Tue, 10 Apr 2012 00:22:01 -0700\r
+Message-ID: <87r4vwhx0m.fsf@servo.finestructure.net>\r
+MIME-Version: 1.0\r
+Content-Type: multipart/signed; boundary="=-=-=";\r
+       micalg=pgp-sha256; protocol="application/pgp-signature"\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://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: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Tue, 10 Apr 2012 07:22:11 -0000\r
+\r
+--=-=-=\r
+Content-Transfer-Encoding: quoted-printable\r
+\r
+On Thu, Apr 05 2012, Peter Wang <novalazy@gmail.com> wrote:\r
+> Add a command to list all configuration items with their associated\r
+> values.\r
+>\r
+> One use is as follows: a MUA may prefer to store data in a central\r
+> notmuch configuration file so that the data is accessible across\r
+> different machines, e.g. an addressbook.  The list command helps\r
+> to implement features such as tab completion on the keys.\r
+> ---\r
+>  notmuch-config.c |   66 ++++++++++++++++++++++++++++++++++++++++++++++++=\r
+++---\r
+>  test/config      |    1 -\r
+>  2 files changed, 62 insertions(+), 5 deletions(-)\r
+>\r
+> diff --git a/notmuch-config.c b/notmuch-config.c\r
+> index 85fc774..d5540ac 100644\r
+> --- a/notmuch-config.c\r
+> +++ b/notmuch-config.c\r
+> @@ -799,20 +799,78 @@ notmuch_config_command_set (void *ctx, char *item, =\r
+int argc, char *argv[])\r
+>      return ret;\r
+>  }\r
+>=20=20\r
+> +static int\r
+> +notmuch_config_command_list (void *ctx)\r
+> +{\r
+> +    notmuch_config_t *config;\r
+> +    char **groups;\r
+> +    size_t g, groups_length;\r
+> +\r
+> +    config =3D notmuch_config_open (ctx, NULL, NULL);\r
+> +    if (config =3D=3D NULL)\r
+> +    return 1;\r
+> +\r
+> +    groups =3D g_key_file_get_groups (config->key_file, &groups_length);\r
+> +    if (groups =3D=3D NULL)\r
+> +    return 1;\r
+> +\r
+> +    for (g =3D 0; g < groups_length; g++) {\r
+> +    char **keys;\r
+> +    size_t k, keys_length;\r
+> +\r
+> +    keys =3D g_key_file_get_keys (config->key_file,\r
+> +                                groups[g], &keys_length, NULL);\r
+> +    if (keys =3D=3D NULL)\r
+> +        continue;\r
+> +\r
+> +    for (k =3D 0; k < keys_length; k++) {\r
+> +        char *value;\r
+> +\r
+> +        value =3D g_key_file_get_string (config->key_file,\r
+> +                                       groups[g], keys[k], NULL);\r
+> +        if (value !=3D NULL) {\r
+> +            printf ("%s.%s=3D%s\n", groups[g], keys[k], value);\r
+> +            free (value);\r
+> +        }\r
+> +    }\r
+> +\r
+> +    g_strfreev (keys);\r
+> +    }\r
+> +\r
+> +    g_strfreev (groups);\r
+> +\r
+> +    notmuch_config_close (config);\r
+> +\r
+> +    return 0;\r
+> +}\r
+> +\r
+>  int\r
+>  notmuch_config_command (void *ctx, int argc, char *argv[])\r
+>  {\r
+>      argc--; argv++; /* skip subcommand argument */\r
+>=20=20\r
+> -    if (argc < 2) {\r
+> -    fprintf (stderr, "Error: notmuch config requires at least two arguments=\r
+.\n");\r
+> +    if (argc < 1) {\r
+> +    fprintf (stderr, "Error: notmuch config requires at least one argument.=\r
+\n");\r
+>      return 1;\r
+>      }\r
+\r
+Hey, Peter.  I would say everything up to here looks great.\r
+\r
+> -    if (strcmp (argv[0], "get") =3D=3D 0)\r
+> +    if (strcmp (argv[0], "get") =3D=3D 0) {\r
+> +    if (argc < 2) {\r
+> +        fprintf (stderr, "Error: notmuch config get requires at least "\r
+> +                 "two arguments.\n");\r
+> +        return 1;\r
+> +    }\r
+>      return notmuch_config_command_get (ctx, argv[1]);\r
+> -    else if (strcmp (argv[0], "set") =3D=3D 0)\r
+> +    } else if (strcmp (argv[0], "set") =3D=3D 0) {\r
+> +    if (argc < 2) {\r
+> +        fprintf (stderr, "Error: notmuch config set requires at least "\r
+> +                 "two arguments.\n");\r
+> +        return 1;\r
+> +    }\r
+>      return notmuch_config_command_set (ctx, argv[1], argc - 2, argv + 2);\r
+\r
+But then these changes look unrelated to me.  They do look good\r
+intentioned, though.  It's probably best to submit these changes in a\r
+separate unrelated patch.\r
+\r
+jamie.\r
+\r
+--=-=-=\r
+Content-Type: application/pgp-signature\r
+\r
+-----BEGIN PGP SIGNATURE-----\r
+Version: GnuPG v1.4.12 (GNU/Linux)\r
+\r
+iQIcBAEBCAAGBQJPg9+aAAoJEO00zqvie6q8svMQAIR79rchJLmp9H04JOjdn8pi\r
+GNMTmW3IXH9mTe4H86vvGbeSHZh2ERp3NR8nFDkjmLD7JMMPagvoGLXA8HLVwlDA\r
+3Fmar/lqIjvbknUjch5Ho/a6hykuzXScO09FPw5Y2B/vr6mWrhcaqUeZ/HHJ5eUc\r
+SFhFT3pN08J54cbOFEUmMEZ5MtVd+JgsweLaKf4rNyXcrYv/0x+8gZbh2kZqVMYn\r
+UAe4ZvvQTmKyDN60dCeutATkhE8BVu6wtDU5dOov11cho9lHj5Oz+VKeTNx2ahok\r
+Nsd5vOHim3uB08L7Y1i8KYfy+wU8a7UDQzoO0LdxkEKpooICLsX3Jk6eVtRUhdg1\r
+64EHzKd55vxMF7psJvw2hoacfVmMHUinMdPjutT0z4RiLhKL1PDyPEv3eA4GBfPN\r
+RkNBXYz9HcP/4LGHsVAQ08xmIeu9+hQpxR0qszJ4m89lBVoQoKMJtJ3ttq5V/mQo\r
+wPX5zGOCWCY4EDzBm0s+OArO88a1bUBbquegN7z0asoucS06Xd3cb4LhmM4TywDV\r
+Meh9k2p337IPpRB2p+qV9TWuud+f9597Z24cAyT+gn9JbKAoE5WVdyzzcBRPWaxU\r
+cmXGwsj8GDvkJ/93Q7S1TQXzPTRrXhY9IislBQUkAKAvoprok6Jc03ZSpSHuw2mC\r
+IfYXph/namcKZi+ETteA\r
+=ZGEU\r
+-----END PGP SIGNATURE-----\r
+--=-=-=--\r