sequencer: simplify away extra git_config_string() call

In our config callback, we call git_config_string() to copy the incoming
value string into a local string. But we don't modify or store that
string; we just look at it and then free it. We can make the code
simpler by just looking at the value passed into the callback.

Note that we do need to check for NULL, which is the one bit of logic
git_config_string() did for us. And I could even see an argument that we
are abstracting any error-checking of the value behind the
git_config_string() layer. But in practice no other callbacks behave
this way; it is standard to check for NULL and then just look at the
string directly.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Jeff King 2023-12-07 02:26:42 -05:00 коммит произвёл Junio C Hamano
Родитель 004c9432f7
Коммит ea8f9494ab
1 изменённых файлов: 8 добавлений и 13 удалений

Просмотреть файл

@ -238,34 +238,29 @@ static int git_sequencer_config(const char *k, const char *v,
const struct config_context *ctx, void *cb)
{
struct replay_opts *opts = cb;
int status;
if (!strcmp(k, "commit.cleanup")) {
const char *s;
if (!v)
return config_error_nonbool(k);
status = git_config_string(&s, k, v);
if (status)
return status;
if (!strcmp(s, "verbatim")) {
if (!strcmp(v, "verbatim")) {
opts->default_msg_cleanup = COMMIT_MSG_CLEANUP_NONE;
opts->explicit_cleanup = 1;
} else if (!strcmp(s, "whitespace")) {
} else if (!strcmp(v, "whitespace")) {
opts->default_msg_cleanup = COMMIT_MSG_CLEANUP_SPACE;
opts->explicit_cleanup = 1;
} else if (!strcmp(s, "strip")) {
} else if (!strcmp(v, "strip")) {
opts->default_msg_cleanup = COMMIT_MSG_CLEANUP_ALL;
opts->explicit_cleanup = 1;
} else if (!strcmp(s, "scissors")) {
} else if (!strcmp(v, "scissors")) {
opts->default_msg_cleanup = COMMIT_MSG_CLEANUP_SCISSORS;
opts->explicit_cleanup = 1;
} else {
warning(_("invalid commit message cleanup mode '%s'"),
s);
v);
}
free((char *)s);
return status;
return 0;
}
if (!strcmp(k, "commit.gpgsign")) {