Re: [PATCH 1/2] cli: abstract common config get/set code

Subject: Re: [PATCH 1/2] cli: abstract common config get/set code

Date: Wed, 15 Jan 2014 09:24:53 -0400

To: Jani Nikula, notmuch@notmuchmail.org

Cc:

From: David Bremner


Jani Nikula <jani@nikula.org> writes:

> Pretty straightforward abstraction similar to get/set list.
> ---
>  notmuch-config.c |   80 ++++++++++++++++++++----------------------------------
>  1 file changed, 29 insertions(+), 51 deletions(-)
>
> diff --git a/notmuch-config.c b/notmuch-config.c
> index befe9b5..305d213 100644
> --- a/notmuch-config.c
> +++ b/notmuch-config.c
> @@ -496,6 +496,29 @@ notmuch_config_is_new (notmuch_config_t *config)
>      return config->is_new;
>  }
>  
> +static const char *
> +_config_get (notmuch_config_t *config, char **field,
> +	     const char *group, const char *key)
> +{
> +    if (*field == NULL) {
> +	char *value;
> +	value = g_key_file_get_string (config->key_file, group, key, NULL);
> +	if (value) {
> +	    *field = talloc_strdup (config, value);
> +	    free (value);
> +	}
> +    }
> +    return *field;
> +}
> +

The use of NULL here is clear enough in the context of the patch, but I
think it deserves a comment in the code; it is not obviously just code
movement after the patch is applied.

Thread: