1 Return-Path: <m.walters@qmul.ac.uk>
\r
2 X-Original-To: notmuch@notmuchmail.org
\r
3 Delivered-To: notmuch@notmuchmail.org
\r
4 Received: from localhost (localhost [127.0.0.1])
\r
5 by olra.theworths.org (Postfix) with ESMTP id 1C675431FBD
\r
6 for <notmuch@notmuchmail.org>; Sat, 18 Jan 2014 05:37:04 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=-1.098 tagged_above=-999 required=5
\r
12 tests=[DKIM_ADSP_CUSTOM_MED=0.001, FREEMAIL_FROM=0.001,
\r
13 NML_ADSP_CUSTOM_MED=1.2, RCVD_IN_DNSWL_MED=-2.3] autolearn=disabled
\r
14 Received: from olra.theworths.org ([127.0.0.1])
\r
15 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
16 with ESMTP id ot2y1al5P3uX for <notmuch@notmuchmail.org>;
\r
17 Sat, 18 Jan 2014 05:36:55 -0800 (PST)
\r
18 Received: from mail2.qmul.ac.uk (mail2.qmul.ac.uk [138.37.6.6])
\r
19 (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))
\r
20 (No client certificate requested)
\r
21 by olra.theworths.org (Postfix) with ESMTPS id 85824431FBC
\r
22 for <notmuch@notmuchmail.org>; Sat, 18 Jan 2014 05:36:55 -0800 (PST)
\r
23 Received: from smtp.qmul.ac.uk ([138.37.6.40])
\r
24 by mail2.qmul.ac.uk with esmtp (Exim 4.71)
\r
25 (envelope-from <m.walters@qmul.ac.uk>)
\r
26 id 1W4W4y-0006gz-8h; Sat, 18 Jan 2014 13:36:52 +0000
\r
27 Received: from 93-97-24-31.zone5.bethere.co.uk ([93.97.24.31] helo=localhost)
\r
28 by smtp.qmul.ac.uk with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.71)
\r
29 (envelope-from <m.walters@qmul.ac.uk>)
\r
30 id 1W4W4x-0007pk-Py; Sat, 18 Jan 2014 13:36:52 +0000
\r
31 From: Mark Walters <markwalters1009@gmail.com>
\r
32 To: Tomi Ollila <tomi.ollila@iki.fi>, Jani Nikula <jani@nikula.org>,
\r
33 notmuch@notmuchmail.org
\r
34 Subject: Re: [PATCH] cli: abstract common config get/set code
\r
35 In-Reply-To: <m24n51cvr6.fsf@guru.guru-group.fi>
\r
36 References: <1389976738-25056-1-git-send-email-jani@nikula.org>
\r
37 <m24n51cvr6.fsf@guru.guru-group.fi>
\r
38 User-Agent: Notmuch/0.15.2+484~gfb59956 (http://notmuchmail.org) Emacs/23.4.1
\r
39 (x86_64-pc-linux-gnu)
\r
40 Date: Sat, 18 Jan 2014 13:36:50 +0000
\r
41 Message-ID: <87iothcsy5.fsf@qmul.ac.uk>
\r
43 Content-Type: text/plain; charset=us-ascii
\r
44 X-Sender-Host-Address: 93.97.24.31
\r
45 X-QM-Geographic: According to ripencc,
\r
46 this message was delivered by a machine in Britain (UK) (GB).
\r
47 X-QM-SPAM-Info: Sender has good ham record. :)
\r
48 X-QM-Body-MD5: 38fb6047ae03a1a1eaa0bbd1fbff5b57 (of first 20000 bytes)
\r
49 X-SpamAssassin-Score: 0.0
\r
50 X-SpamAssassin-SpamBar: /
\r
51 X-SpamAssassin-Report: The QM spam filters have analysed this message to
\r
53 spam. We require at least 5.0 points to mark a message as spam.
\r
54 This message scored 0.0 points. Summary of the scoring:
\r
55 * 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail
\r
56 provider * (markwalters1009[at]gmail.com)
\r
57 * 0.0 AWL AWL: From: address is in the auto white-list
\r
58 X-QM-Scan-Virus: ClamAV says the message is clean
\r
59 X-BeenThere: notmuch@notmuchmail.org
\r
60 X-Mailman-Version: 2.1.13
\r
62 List-Id: "Use and development of the notmuch mail system."
\r
63 <notmuch.notmuchmail.org>
\r
64 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
65 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
66 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
67 List-Post: <mailto:notmuch@notmuchmail.org>
\r
68 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
69 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
70 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
71 X-List-Received-Date: Sat, 18 Jan 2014 13:37:04 -0000
\r
78 On Sat, 18 Jan 2014, Tomi Ollila <tomi.ollila@iki.fi> wrote:
\r
79 > On Fri, Jan 17 2014, Jani Nikula <jani@nikula.org> wrote:
\r
81 >> Pretty straightforward abstraction similar to get/set list.
\r
88 >> v2 of id:1376839205-5115-1-git-send-email-jani@nikula.org adding a few
\r
89 >> comments about config value caching per David's request. Dropped the
\r
90 >> 2nd patch as too tricky.
\r
92 >> notmuch-config.c | 86 +++++++++++++++++++++++---------------------------------
\r
93 >> 1 file changed, 35 insertions(+), 51 deletions(-)
\r
95 >> diff --git a/notmuch-config.c b/notmuch-config.c
\r
96 >> index 6845e3c..4aad9eb 100644
\r
97 >> --- a/notmuch-config.c
\r
98 >> +++ b/notmuch-config.c
\r
99 >> @@ -496,6 +496,32 @@ notmuch_config_is_new (notmuch_config_t *config)
\r
100 >> return config->is_new;
\r
103 >> +static const char *
\r
104 >> +_config_get (notmuch_config_t *config, char **field,
\r
105 >> + const char *group, const char *key)
\r
107 >> + /* read from config file and cache value, if not cached already */
\r
108 >> + if (*field == NULL) {
\r
110 >> + value = g_key_file_get_string (config->key_file, group, key, NULL);
\r
112 >> + *field = talloc_strdup (config, value);
\r
116 >> + return *field;
\r
120 >> +_config_set (notmuch_config_t *config, char **field,
\r
121 >> + const char *group, const char *key, const char *value)
\r
123 >> + g_key_file_set_string (config->key_file, group, key, value);
\r
125 >> + /* drop the cached value */
\r
126 >> + talloc_free (*field);
\r
127 >> + *field = NULL;
\r
130 >> static const char **
\r
131 >> _config_get_list (notmuch_config_t *config,
\r
132 >> @@ -504,6 +530,7 @@ _config_get_list (notmuch_config_t *config,
\r
134 >> assert(outlist);
\r
136 >> + /* read from config file and cache value, if not cached already */
\r
137 >> if (*outlist == NULL) {
\r
139 >> char **inlist = g_key_file_get_string_list (config->key_file,
\r
140 >> @@ -535,6 +562,8 @@ _config_set_list (notmuch_config_t *config,
\r
141 >> size_t length, const char ***config_var )
\r
143 >> g_key_file_set_string_list (config->key_file, group, name, list, length);
\r
145 >> + /* drop the cached value */
\r
146 >> talloc_free (*config_var);
\r
147 >> *config_var = NULL;
\r
149 >> @@ -542,85 +571,40 @@ _config_set_list (notmuch_config_t *config,
\r
151 >> notmuch_config_get_database_path (notmuch_config_t *config)
\r
155 >> - if (config->database_path == NULL) {
\r
156 >> - path = g_key_file_get_string (config->key_file,
\r
157 >> - "database", "path", NULL);
\r
159 >> - config->database_path = talloc_strdup (config, path);
\r
164 >> - return config->database_path;
\r
165 >> + return _config_get (config, &config->database_path, "database", "path");
\r
169 >> notmuch_config_set_database_path (notmuch_config_t *config,
\r
170 >> const char *database_path)
\r
172 >> - g_key_file_set_string (config->key_file,
\r
173 >> - "database", "path", database_path);
\r
175 >> - talloc_free (config->database_path);
\r
176 >> - config->database_path = NULL;
\r
177 >> + _config_set (config, &config->database_path, "database", "path", database_path);
\r
181 >> notmuch_config_get_user_name (notmuch_config_t *config)
\r
185 >> - if (config->user_name == NULL) {
\r
186 >> - name = g_key_file_get_string (config->key_file,
\r
187 >> - "user", "name", NULL);
\r
189 >> - config->user_name = talloc_strdup (config, name);
\r
194 >> - return config->user_name;
\r
195 >> + return _config_get (config, &config->user_name, "user", "name");
\r
199 >> notmuch_config_set_user_name (notmuch_config_t *config,
\r
200 >> const char *user_name)
\r
202 >> - g_key_file_set_string (config->key_file,
\r
203 >> - "user", "name", user_name);
\r
205 >> - talloc_free (config->user_name);
\r
206 >> - config->user_name = NULL;
\r
207 >> + _config_set (config, &config->user_name, "user", "name", user_name);
\r
211 >> notmuch_config_get_user_primary_email (notmuch_config_t *config)
\r
215 >> - if (config->user_primary_email == NULL) {
\r
216 >> - email = g_key_file_get_string (config->key_file,
\r
217 >> - "user", "primary_email", NULL);
\r
219 >> - config->user_primary_email = talloc_strdup (config, email);
\r
224 >> - return config->user_primary_email;
\r
225 >> + return _config_get (config, &config->user_primary_email, "user", "primary_email");
\r
229 >> notmuch_config_set_user_primary_email (notmuch_config_t *config,
\r
230 >> const char *primary_email)
\r
232 >> - g_key_file_set_string (config->key_file,
\r
233 >> - "user", "primary_email", primary_email);
\r
235 >> - talloc_free (config->user_primary_email);
\r
236 >> - config->user_primary_email = NULL;
\r
237 >> + _config_set (config, &config->user_primary_email, "user", "primary_email", primary_email);
\r
244 >> _______________________________________________
\r
245 >> notmuch mailing list
\r
246 >> notmuch@notmuchmail.org
\r
247 >> http://notmuchmail.org/mailman/listinfo/notmuch
\r
248 > _______________________________________________
\r
249 > notmuch mailing list
\r
250 > notmuch@notmuchmail.org
\r
251 > http://notmuchmail.org/mailman/listinfo/notmuch
\r