imap-send.c: replace `git_config()` with `git_config_get_*()` family

Use `git_config_get_*()` family instead of `git_config()` to take advantage of the config-set API which provides a cleaner control flow. Signed-off-by: Tanay Abhra <tanayabh@gmail.com> Reviewed-by: Matthieu Moy <Matthieu.Moy@imag.fr> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Tanay Abhra committed Aug 7, 2014 at 09:21 UTC ef7e1d0cdac8f55290f60c78dca00bfb84e7a925
1 file changed +26 -34
imap-send.c
+26 -34
@@ -1326,43 +1326,35 @@ static int split_msg(struct strbuf *all_msgs, struct strbuf *msg, int *ofs)
1326
1327 static char *imap_folder;
1328
1329 -static int git_imap_config(const char *key, const char *val, void *cb)
1329 +static void git_imap_config(void)
1330 {
1331 - if (!skip_prefix(key, "imap.", &key))
1332 - return 0;
1331 + const char *val = NULL;
1332 +
1333 + git_config_get_bool("imap.sslverify", &server.ssl_verify);
1334 + git_config_get_bool("imap.preformattedhtml", &server.use_html);
1335 + git_config_get_string("imap.folder", &imap_folder);
1336
1334 - /* check booleans first, and barf on others */
1335 - if (!strcmp("sslverify", key))
1336 - server.ssl_verify = git_config_bool(key, val);
1337 - else if (!strcmp("preformattedhtml", key))
1338 - server.use_html = git_config_bool(key, val);
1339 - else if (!val)
1340 - return config_error_nonbool(key);
1341 -
1342 - if (!strcmp("folder", key)) {
1343 - imap_folder = xstrdup(val);
1344 - } else if (!strcmp("host", key)) {
1345 - if (starts_with(val, "imap:"))
1346 - val += 5;
1347 - else if (starts_with(val, "imaps:")) {
1348 - val += 6;
1349 - server.use_ssl = 1;
1337 + if (!git_config_get_value("imap.host", &val)) {
1338 + if (!val) {
1339 + git_die_config("imap.host", "Missing value for 'imap.host'");
1340 + } else {
1341 + if (starts_with(val, "imap:"))
1342 + val += 5;
1343 + else if (starts_with(val, "imaps:")) {
1344 + val += 6;
1345 + server.use_ssl = 1;
1346 + }
1347 + if (starts_with(val, "//"))
1348 + val += 2;
1349 + server.host = xstrdup(val);
1350 }
1351 - if (starts_with(val, "//"))
1352 - val += 2;
1353 - server.host = xstrdup(val);
1354 - } else if (!strcmp("user", key))
1355 - server.user = xstrdup(val);
1356 - else if (!strcmp("pass", key))
1357 - server.pass = xstrdup(val);
1358 - else if (!strcmp("port", key))
1359 - server.port = git_config_int(key, val);
1360 - else if (!strcmp("tunnel", key))
1361 - server.tunnel = xstrdup(val);
1362 - else if (!strcmp("authmethod", key))
1363 - server.auth_method = xstrdup(val);
1351 + }
1352
1365 - return 0;
1353 + git_config_get_string("imap.user", &server.user);
1354 + git_config_get_string("imap.pass", &server.pass);
1355 + git_config_get_int("imap.port", &server.port);
1356 + git_config_get_string("imap.tunnel", &server.tunnel);
1357 + git_config_get_string("imap.authmethod", &server.auth_method);
1358 }
1359
1360 int main(int argc, char **argv)
@@ -1383,7 +1375,7 @@ int main(int argc, char **argv)
1375 usage(imap_send_usage);
1376
1377 setup_git_directory_gently(&nongit_ok);
1386 - git_config(git_imap_config, NULL);
1378 + git_imap_config();
1379
1380 if (!server.port)
1381 server.port = server.use_ssl ? 993 : 143;