Skip to content

Commit ea8f949

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 004c943 commit ea8f949

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

sequencer.c

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -238,34 +238,29 @@ static int git_sequencer_config(const char *k, const char *v,
238238
const struct config_context *ctx, void *cb)
239239
{
240240
struct replay_opts *opts = cb;
241-
int status;
242241

243242
if (!strcmp(k, "commit.cleanup")) {
244-
const char *s;
243+
if (!v)
244+
return config_error_nonbool(k);
245245

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")) {
251247
opts->default_msg_cleanup = COMMIT_MSG_CLEANUP_NONE;
252248
opts->explicit_cleanup = 1;
253-
} else if (!strcmp(s, "whitespace")) {
249+
} else if (!strcmp(v, "whitespace")) {
254250
opts->default_msg_cleanup = COMMIT_MSG_CLEANUP_SPACE;
255251
opts->explicit_cleanup = 1;
256-
} else if (!strcmp(s, "strip")) {
252+
} else if (!strcmp(v, "strip")) {
257253
opts->default_msg_cleanup = COMMIT_MSG_CLEANUP_ALL;
258254
opts->explicit_cleanup = 1;
259-
} else if (!strcmp(s, "scissors")) {
255+
} else if (!strcmp(v, "scissors")) {
260256
opts->default_msg_cleanup = COMMIT_MSG_CLEANUP_SCISSORS;
261257
opts->explicit_cleanup = 1;
262258
} else {
263259
warning(_("invalid commit message cleanup mode '%s'"),
264-
s);
260+
v);
265261
}
266262

267-
free((char *)s);
268-
return status;
263+
return 0;
269264
}
270265

271266
if (!strcmp(k, "commit.gpgsign")) {

0 commit comments

Comments
 (0)