1 Return-Path: <jani@nikula.org>
\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 578C7421161
\r
6 for <notmuch@notmuchmail.org>; Sun, 18 Aug 2013 08:20:09 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5
\r
12 tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled
\r
13 Received: from olra.theworths.org ([127.0.0.1])
\r
14 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
15 with ESMTP id tF2-jhiNVfu0 for <notmuch@notmuchmail.org>;
\r
16 Sun, 18 Aug 2013 08:20:03 -0700 (PDT)
\r
17 Received: from mail-bk0-f42.google.com (mail-bk0-f42.google.com
\r
18 [209.85.214.42]) (using TLSv1 with cipher RC4-SHA (128/128 bits))
\r
19 (No client certificate requested)
\r
20 by olra.theworths.org (Postfix) with ESMTPS id A2643431FDB
\r
21 for <notmuch@notmuchmail.org>; Sun, 18 Aug 2013 08:20:03 -0700 (PDT)
\r
22 Received: by mail-bk0-f42.google.com with SMTP id my10so1149927bkb.15
\r
23 for <notmuch@notmuchmail.org>; Sun, 18 Aug 2013 08:20:02 -0700 (PDT)
\r
24 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
\r
25 d=google.com; s=20120113;
\r
26 h=x-gm-message-state:from:to:cc:subject:date:message-id;
\r
27 bh=TBmMXK6A1uOEclkvE4Y9Fkd7wwtTW/kPnPShADis+z8=;
\r
28 b=JtkT3tlft7sSpM59+W98hXJnLltIhEa5mgmqhPev/bjyTB4WQLbBcS1SMdy2vtilZF
\r
29 KAKJBDs9wkkVnTaizV7lYBhOQ0srVIGDp6IKB0nqWC2rWLefESO0A4gGrivzFJGeEbVD
\r
30 gukAmvNMN0gJHXky6jLOHHyeRPhH/VpB6jyzUBeH0b0J7svxZvPVkZhAJ1d2BHhCA/yY
\r
31 a0n+xSWplbYyvy3EkU0Xi0fYGxqJZedyU8DvDLMCZJb1hAfUiO2z8wYT1D2Qb2K8wWic
\r
32 IMjFPVMTPFOFHLtn9vs5tIGV9r2Pnp3UJcmyCldqIMsHIDe9MlhM2BShC1rKEsbeyU5Y
\r
35 ALoCoQk9uEvZlGyq8kGQuSmrzA36DauMGDLM7WUaZ2C/0jZV302hIuNSpgXJGHpLnNNO45LpLWTC
\r
36 X-Received: by 10.204.70.1 with SMTP id b1mr4827999bkj.3.1376839202312;
\r
37 Sun, 18 Aug 2013 08:20:02 -0700 (PDT)
\r
38 Received: from localhost (dsl-hkibrasgw2-58c36f-91.dhcp.inet.fi.
\r
40 by mx.google.com with ESMTPSA id ku9sm951140bkb.1.1969.12.31.16.00.00
\r
41 (version=TLSv1.2 cipher=RC4-SHA bits=128/128);
\r
42 Sun, 18 Aug 2013 08:20:01 -0700 (PDT)
\r
43 From: Jani Nikula <jani@nikula.org>
\r
44 To: notmuch@notmuchmail.org
\r
45 Subject: [PATCH 1/2] cli: abstract common config get/set code
\r
46 Date: Sun, 18 Aug 2013 18:20:04 +0300
\r
47 Message-Id: <1376839205-5115-1-git-send-email-jani@nikula.org>
\r
48 X-Mailer: git-send-email 1.7.10.4
\r
49 X-BeenThere: notmuch@notmuchmail.org
\r
50 X-Mailman-Version: 2.1.13
\r
52 List-Id: "Use and development of the notmuch mail system."
\r
53 <notmuch.notmuchmail.org>
\r
54 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
55 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
56 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
57 List-Post: <mailto:notmuch@notmuchmail.org>
\r
58 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
59 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
60 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
61 X-List-Received-Date: Sun, 18 Aug 2013 15:20:09 -0000
\r
63 Pretty straightforward abstraction similar to get/set list.
\r
65 notmuch-config.c | 80 ++++++++++++++++++++----------------------------------
\r
66 1 file changed, 29 insertions(+), 51 deletions(-)
\r
68 diff --git a/notmuch-config.c b/notmuch-config.c
\r
69 index befe9b5..305d213 100644
\r
70 --- a/notmuch-config.c
\r
71 +++ b/notmuch-config.c
\r
72 @@ -496,6 +496,29 @@ notmuch_config_is_new (notmuch_config_t *config)
\r
73 return config->is_new;
\r
76 +static const char *
\r
77 +_config_get (notmuch_config_t *config, char **field,
\r
78 + const char *group, const char *key)
\r
80 + if (*field == NULL) {
\r
82 + value = g_key_file_get_string (config->key_file, group, key, NULL);
\r
84 + *field = talloc_strdup (config, value);
\r
92 +_config_set (notmuch_config_t *config, char **field,
\r
93 + const char *group, const char *key, const char *value)
\r
95 + g_key_file_set_string (config->key_file, group, key, value);
\r
96 + talloc_free (*field);
\r
100 static const char **
\r
101 _config_get_list (notmuch_config_t *config,
\r
102 @@ -542,85 +565,40 @@ _config_set_list (notmuch_config_t *config,
\r
104 notmuch_config_get_database_path (notmuch_config_t *config)
\r
108 - if (config->database_path == NULL) {
\r
109 - path = g_key_file_get_string (config->key_file,
\r
110 - "database", "path", NULL);
\r
112 - config->database_path = talloc_strdup (config, path);
\r
117 - return config->database_path;
\r
118 + return _config_get (config, &config->database_path, "database", "path");
\r
122 notmuch_config_set_database_path (notmuch_config_t *config,
\r
123 const char *database_path)
\r
125 - g_key_file_set_string (config->key_file,
\r
126 - "database", "path", database_path);
\r
128 - talloc_free (config->database_path);
\r
129 - config->database_path = NULL;
\r
130 + _config_set (config, &config->database_path, "database", "path", database_path);
\r
134 notmuch_config_get_user_name (notmuch_config_t *config)
\r
138 - if (config->user_name == NULL) {
\r
139 - name = g_key_file_get_string (config->key_file,
\r
140 - "user", "name", NULL);
\r
142 - config->user_name = talloc_strdup (config, name);
\r
147 - return config->user_name;
\r
148 + return _config_get (config, &config->user_name, "user", "name");
\r
152 notmuch_config_set_user_name (notmuch_config_t *config,
\r
153 const char *user_name)
\r
155 - g_key_file_set_string (config->key_file,
\r
156 - "user", "name", user_name);
\r
158 - talloc_free (config->user_name);
\r
159 - config->user_name = NULL;
\r
160 + _config_set (config, &config->user_name, "user", "name", user_name);
\r
164 notmuch_config_get_user_primary_email (notmuch_config_t *config)
\r
168 - if (config->user_primary_email == NULL) {
\r
169 - email = g_key_file_get_string (config->key_file,
\r
170 - "user", "primary_email", NULL);
\r
172 - config->user_primary_email = talloc_strdup (config, email);
\r
177 - return config->user_primary_email;
\r
178 + return _config_get (config, &config->user_primary_email, "user", "primary_email");
\r
182 notmuch_config_set_user_primary_email (notmuch_config_t *config,
\r
183 const char *primary_email)
\r
185 - g_key_file_set_string (config->key_file,
\r
186 - "user", "primary_email", primary_email);
\r
188 - talloc_free (config->user_primary_email);
\r
189 - config->user_primary_email = NULL;
\r
190 + _config_set (config, &config->user_primary_email, "user", "primary_email", primary_email);
\r