Skip to content

Commit ef7e1d0

Browse files
tanayabhgitster
authored andcommitted
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 <[email protected]> Reviewed-by: Matthieu Moy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 586f414 commit ef7e1d0

File tree

1 file changed

+26
-34
lines changed

1 file changed

+26
-34
lines changed

Diff for: imap-send.c

+26-34
Original file line numberDiff line numberDiff line change
@@ -1326,43 +1326,35 @@ static int split_msg(struct strbuf *all_msgs, struct strbuf *msg, int *ofs)
13261326

13271327
static char *imap_folder;
13281328

1329-
static int git_imap_config(const char *key, const char *val, void *cb)
1329+
static void git_imap_config(void)
13301330
{
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);
13331336

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);
13501350
}
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+
}
13641352

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);
13661358
}
13671359

13681360
int main(int argc, char **argv)
@@ -1383,7 +1375,7 @@ int main(int argc, char **argv)
13831375
usage(imap_send_usage);
13841376

13851377
setup_git_directory_gently(&nongit_ok);
1386-
git_config(git_imap_config, NULL);
1378+
git_imap_config();
13871379

13881380
if (!server.port)
13891381
server.port = server.use_ssl ? 993 : 143;

0 commit comments

Comments
 (0)