--- /dev/null
+Return-Path: <tomi.ollila@iki.fi>\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 1AB8D431FBD\r
+ for <notmuch@notmuchmail.org>; Sat, 18 Jan 2014 04:36:30 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
+ 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 5FAO6kmOFY34 for <notmuch@notmuchmail.org>;\r
+ Sat, 18 Jan 2014 04:36:22 -0800 (PST)\r
+Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34])\r
+ by olra.theworths.org (Postfix) with ESMTP id AD505431FBC\r
+ for <notmuch@notmuchmail.org>; Sat, 18 Jan 2014 04:36:21 -0800 (PST)\r
+Received: from guru.guru-group.fi (localhost [IPv6:::1])\r
+ by guru.guru-group.fi (Postfix) with ESMTP id 8FCE5100086;\r
+ Sat, 18 Jan 2014 14:36:13 +0200 (EET)\r
+From: Tomi Ollila <tomi.ollila@iki.fi>\r
+To: Jani Nikula <jani@nikula.org>, notmuch@notmuchmail.org\r
+Subject: Re: [PATCH] cli: abstract common config get/set code\r
+In-Reply-To: <1389976738-25056-1-git-send-email-jani@nikula.org>\r
+References: <1389976738-25056-1-git-send-email-jani@nikula.org>\r
+User-Agent: Notmuch/0.17+34~g98b959f (http://notmuchmail.org) Emacs/24.3.1\r
+ (x86_64-unknown-linux-gnu)\r
+X-Face: HhBM'cA~<r"^Xv\KRN0P{vn'Y"Kd;zg_y3S[4)KSN~s?O\"QPoL\r
+ $[Xv_BD:i/F$WiEWax}R(MPS`^UaptOGD`*/=@\1lKoVa9tnrg0TW?"r7aRtgk[F\r
+ !)g;OY^,BjTbr)Np:%c_o'jj,Z\r
+Date: Sat, 18 Jan 2014 14:36:13 +0200\r
+Message-ID: <m24n51cvr6.fsf@guru.guru-group.fi>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain\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 12:36:30 -0000\r
+\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