--- /dev/null
+Return-Path: <m.walters@qmul.ac.uk>\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 1C675431FBD\r
+ for <notmuch@notmuchmail.org>; Sat, 18 Jan 2014 05:37:04 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -1.098\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-1.098 tagged_above=-999 required=5\r
+ tests=[DKIM_ADSP_CUSTOM_MED=0.001, FREEMAIL_FROM=0.001,\r
+ NML_ADSP_CUSTOM_MED=1.2, RCVD_IN_DNSWL_MED=-2.3] 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 ot2y1al5P3uX for <notmuch@notmuchmail.org>;\r
+ Sat, 18 Jan 2014 05:36:55 -0800 (PST)\r
+Received: from mail2.qmul.ac.uk (mail2.qmul.ac.uk [138.37.6.6])\r
+ (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id 85824431FBC\r
+ for <notmuch@notmuchmail.org>; Sat, 18 Jan 2014 05:36:55 -0800 (PST)\r
+Received: from smtp.qmul.ac.uk ([138.37.6.40])\r
+ by mail2.qmul.ac.uk with esmtp (Exim 4.71)\r
+ (envelope-from <m.walters@qmul.ac.uk>)\r
+ id 1W4W4y-0006gz-8h; Sat, 18 Jan 2014 13:36:52 +0000\r
+Received: from 93-97-24-31.zone5.bethere.co.uk ([93.97.24.31] helo=localhost)\r
+ by smtp.qmul.ac.uk with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.71)\r
+ (envelope-from <m.walters@qmul.ac.uk>)\r
+ id 1W4W4x-0007pk-Py; Sat, 18 Jan 2014 13:36:52 +0000\r
+From: Mark Walters <markwalters1009@gmail.com>\r
+To: Tomi Ollila <tomi.ollila@iki.fi>, Jani Nikula <jani@nikula.org>,\r
+ notmuch@notmuchmail.org\r
+Subject: Re: [PATCH] cli: abstract common config get/set code\r
+In-Reply-To: <m24n51cvr6.fsf@guru.guru-group.fi>\r
+References: <1389976738-25056-1-git-send-email-jani@nikula.org>\r
+ <m24n51cvr6.fsf@guru.guru-group.fi>\r
+User-Agent: Notmuch/0.15.2+484~gfb59956 (http://notmuchmail.org) Emacs/23.4.1\r
+ (x86_64-pc-linux-gnu)\r
+Date: Sat, 18 Jan 2014 13:36:50 +0000\r
+Message-ID: <87iothcsy5.fsf@qmul.ac.uk>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=us-ascii\r
+X-Sender-Host-Address: 93.97.24.31\r
+X-QM-Geographic: According to ripencc,\r
+ this message was delivered by a machine in Britain (UK) (GB).\r
+X-QM-SPAM-Info: Sender has good ham record. :)\r
+X-QM-Body-MD5: 38fb6047ae03a1a1eaa0bbd1fbff5b57 (of first 20000 bytes)\r
+X-SpamAssassin-Score: 0.0\r
+X-SpamAssassin-SpamBar: /\r
+X-SpamAssassin-Report: The QM spam filters have analysed this message to\r
+ determine if it is\r
+ spam. We require at least 5.0 points to mark a message as spam.\r
+ This message scored 0.0 points. Summary of the scoring: \r
+ * 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail\r
+ provider * (markwalters1009[at]gmail.com)\r
+ * 0.0 AWL AWL: From: address is in the auto white-list\r
+X-QM-Scan-Virus: ClamAV says the message is clean\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: Sat, 18 Jan 2014 13:37:04 -0000\r
+\r
+\r
+LGTM too\r
+\r
+Mark\r
+\r
+On Sat, 18 Jan 2014, Tomi Ollila <tomi.ollila@iki.fi> wrote:\r
+> On Fri, Jan 17 2014, Jani Nikula <jani@nikula.org> wrote:\r
+>\r
+>> Pretty straightforward abstraction similar to get/set list.\r
+>>\r
+>> ---\r
+>\r
+> LGTM. tests pass.\r
+>\r
+>>\r
+>> v2 of id:1376839205-5115-1-git-send-email-jani@nikula.org adding a few\r
+>> comments about config value caching per David's request. Dropped the\r
+>> 2nd patch as too tricky.\r
+>> ---\r
+>> notmuch-config.c | 86 +++++++++++++++++++++++---------------------------------\r
+>> 1 file changed, 35 insertions(+), 51 deletions(-)\r
+>>\r
+>> diff --git a/notmuch-config.c b/notmuch-config.c\r
+>> index 6845e3c..4aad9eb 100644\r
+>> --- a/notmuch-config.c\r
+>> +++ b/notmuch-config.c\r
+>> @@ -496,6 +496,32 @@ notmuch_config_is_new (notmuch_config_t *config)\r
+>> return config->is_new;\r
+>> }\r
+>>\r
+>> +static const char *\r
+>> +_config_get (notmuch_config_t *config, char **field,\r
+>> + const char *group, const char *key)\r
+>> +{\r
+>> + /* read from config file and cache value, if not cached already */\r
+>> + if (*field == NULL) {\r
+>> + char *value;\r
+>> + value = g_key_file_get_string (config->key_file, group, key, NULL);\r
+>> + if (value) {\r
+>> + *field = talloc_strdup (config, value);\r
+>> + free (value);\r
+>> + }\r
+>> + }\r
+>> + return *field;\r
+>> +}\r
+>> +\r
+>> +static void\r
+>> +_config_set (notmuch_config_t *config, char **field,\r
+>> + const char *group, const char *key, const char *value)\r
+>> +{\r
+>> + g_key_file_set_string (config->key_file, group, key, value);\r
+>> +\r
+>> + /* drop the cached value */\r
+>> + talloc_free (*field);\r
+>> + *field = NULL;\r
+>> +}\r
+>>\r
+>> static const char **\r
+>> _config_get_list (notmuch_config_t *config,\r
+>> @@ -504,6 +530,7 @@ _config_get_list (notmuch_config_t *config,\r
+>> {\r
+>> assert(outlist);\r
+>>\r
+>> + /* read from config file and cache value, if not cached already */\r
+>> if (*outlist == NULL) {\r
+>>\r
+>> char **inlist = g_key_file_get_string_list (config->key_file,\r
+>> @@ -535,6 +562,8 @@ _config_set_list (notmuch_config_t *config,\r
+>> size_t length, const char ***config_var )\r
+>> {\r
+>> g_key_file_set_string_list (config->key_file, group, name, list, length);\r
+>> +\r
+>> + /* drop the cached value */\r
+>> talloc_free (*config_var);\r
+>> *config_var = NULL;\r
+>> }\r
+>> @@ -542,85 +571,40 @@ _config_set_list (notmuch_config_t *config,\r
+>> const char *\r
+>> notmuch_config_get_database_path (notmuch_config_t *config)\r
+>> {\r
+>> - char *path;\r
+>> -\r
+>> - if (config->database_path == NULL) {\r
+>> - path = g_key_file_get_string (config->key_file,\r
+>> - "database", "path", NULL);\r
+>> - if (path) {\r
+>> - config->database_path = talloc_strdup (config, path);\r
+>> - free (path);\r
+>> - }\r
+>> - }\r
+>> -\r
+>> - return config->database_path;\r
+>> + return _config_get (config, &config->database_path, "database", "path");\r
+>> }\r
+>>\r
+>> void\r
+>> notmuch_config_set_database_path (notmuch_config_t *config,\r
+>> const char *database_path)\r
+>> {\r
+>> - g_key_file_set_string (config->key_file,\r
+>> - "database", "path", database_path);\r
+>> -\r
+>> - talloc_free (config->database_path);\r
+>> - config->database_path = NULL;\r
+>> + _config_set (config, &config->database_path, "database", "path", database_path);\r
+>> }\r
+>>\r
+>> const char *\r
+>> notmuch_config_get_user_name (notmuch_config_t *config)\r
+>> {\r
+>> - char *name;\r
+>> -\r
+>> - if (config->user_name == NULL) {\r
+>> - name = g_key_file_get_string (config->key_file,\r
+>> - "user", "name", NULL);\r
+>> - if (name) {\r
+>> - config->user_name = talloc_strdup (config, name);\r
+>> - free (name);\r
+>> - }\r
+>> - }\r
+>> -\r
+>> - return config->user_name;\r
+>> + return _config_get (config, &config->user_name, "user", "name");\r
+>> }\r
+>>\r
+>> void\r
+>> notmuch_config_set_user_name (notmuch_config_t *config,\r
+>> const char *user_name)\r
+>> {\r
+>> - g_key_file_set_string (config->key_file,\r
+>> - "user", "name", user_name);\r
+>> -\r
+>> - talloc_free (config->user_name);\r
+>> - config->user_name = NULL;\r
+>> + _config_set (config, &config->user_name, "user", "name", user_name);\r
+>> }\r
+>>\r
+>> const char *\r
+>> notmuch_config_get_user_primary_email (notmuch_config_t *config)\r
+>> {\r
+>> - char *email;\r
+>> -\r
+>> - if (config->user_primary_email == NULL) {\r
+>> - email = g_key_file_get_string (config->key_file,\r
+>> - "user", "primary_email", NULL);\r
+>> - if (email) {\r
+>> - config->user_primary_email = talloc_strdup (config, email);\r
+>> - free (email);\r
+>> - }\r
+>> - }\r
+>> -\r
+>> - return config->user_primary_email;\r
+>> + return _config_get (config, &config->user_primary_email, "user", "primary_email");\r
+>> }\r
+>>\r
+>> void\r
+>> notmuch_config_set_user_primary_email (notmuch_config_t *config,\r
+>> const char *primary_email)\r
+>> {\r
+>> - g_key_file_set_string (config->key_file,\r
+>> - "user", "primary_email", primary_email);\r
+>> -\r
+>> - talloc_free (config->user_primary_email);\r
+>> - config->user_primary_email = NULL;\r
+>> + _config_set (config, &config->user_primary_email, "user", "primary_email", primary_email);\r
+>> }\r
+>>\r
+>> const char **\r
+>> --\r
+>> 1.8.5.2\r
+>>\r
+>> _______________________________________________\r
+>> notmuch mailing list\r
+>> notmuch@notmuchmail.org\r
+>> http://notmuchmail.org/mailman/listinfo/notmuch\r
+> _______________________________________________\r
+> notmuch mailing list\r
+> notmuch@notmuchmail.org\r
+> http://notmuchmail.org/mailman/listinfo/notmuch\r