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>
Jeff King committed
Dec 7, 2023 at 02:26 UTC
ea8f9494aba052fd531f674f78dba55f084bdc34
1 file changed
+8
-13
sequencer.c
+8
-13
@@ -238,34 +238,29 @@ static int git_sequencer_config(const char *k, const char *v,
238
const struct config_context *ctx, void *cb)
239
{
240
struct replay_opts *opts = cb;
241
- int status;
241
242
if (!strcmp(k, "commit.cleanup")) {
244
- const char *s;
243
+ if (!v)
244
+ return config_error_nonbool(k);
245
246
- status = git_config_string(&s, k, v);
247
- if (status)
248
- return status;
249
-
250
- if (!strcmp(s, "verbatim")) {
246
+ if (!strcmp(v, "verbatim")) {
247
opts->default_msg_cleanup = COMMIT_MSG_CLEANUP_NONE;
248
opts->explicit_cleanup = 1;
253
- } else if (!strcmp(s, "whitespace")) {
249
+ } else if (!strcmp(v, "whitespace")) {
250
opts->default_msg_cleanup = COMMIT_MSG_CLEANUP_SPACE;
251
opts->explicit_cleanup = 1;
256
- } else if (!strcmp(s, "strip")) {
252
+ } else if (!strcmp(v, "strip")) {
253
opts->default_msg_cleanup = COMMIT_MSG_CLEANUP_ALL;
254
opts->explicit_cleanup = 1;
259
- } else if (!strcmp(s, "scissors")) {
255
+ } else if (!strcmp(v, "scissors")) {
256
opts->default_msg_cleanup = COMMIT_MSG_CLEANUP_SCISSORS;
257
opts->explicit_cleanup = 1;
258
} else {
259
warning(_("invalid commit message cleanup mode '%s'"),
264
- s);
260
+ v);
261
}
262
267
- free((char *)s);
268
- return status;
263
+ return 0;
264
}
265
266
if (!strcmp(k, "commit.gpgsign")) {