Skip to content

Commit 44ee006

Browse files
committed
Merge branch 'jk/config-cleanup' into next
Code clean-up around use of configuration variables. * jk/config-cleanup: sequencer: simplify away extra git_config_string() call gpg-interface: drop pointless config_error_nonbool() checks push: drop confusing configset/callback redundancy config: use git_config_string() for core.checkRoundTripEncoding diff: give more detailed messages for bogus diff.* config config: use config_error_nonbool() instead of custom messages imap-send: don't use git_die_config() inside callback git_xmerge_config(): prefer error() to die() config: reject bogus values for core.checkstat
2 parents 2a42fdc + ea8f949 commit 44ee006

File tree

11 files changed

+55
-73
lines changed

11 files changed

+55
-73
lines changed

builtin/push.c

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -526,26 +526,21 @@ static int git_push_config(const char *k, const char *v,
526526
*flags |= TRANSPORT_PUSH_AUTO_UPSTREAM;
527527
return 0;
528528
} else if (!strcmp(k, "push.gpgsign")) {
529-
const char *value;
530-
if (!git_config_get_value("push.gpgsign", &value)) {
531-
switch (git_parse_maybe_bool(value)) {
532-
case 0:
533-
set_push_cert_flags(flags, SEND_PACK_PUSH_CERT_NEVER);
534-
break;
535-
case 1:
536-
set_push_cert_flags(flags, SEND_PACK_PUSH_CERT_ALWAYS);
537-
break;
538-
default:
539-
if (value && !strcasecmp(value, "if-asked"))
540-
set_push_cert_flags(flags, SEND_PACK_PUSH_CERT_IF_ASKED);
541-
else
542-
return error(_("invalid value for '%s'"), k);
543-
}
529+
switch (git_parse_maybe_bool(v)) {
530+
case 0:
531+
set_push_cert_flags(flags, SEND_PACK_PUSH_CERT_NEVER);
532+
break;
533+
case 1:
534+
set_push_cert_flags(flags, SEND_PACK_PUSH_CERT_ALWAYS);
535+
break;
536+
default:
537+
if (!strcasecmp(v, "if-asked"))
538+
set_push_cert_flags(flags, SEND_PACK_PUSH_CERT_IF_ASKED);
539+
else
540+
return error(_("invalid value for '%s'"), k);
544541
}
545542
} else if (!strcmp(k, "push.recursesubmodules")) {
546-
const char *value;
547-
if (!git_config_get_value("push.recursesubmodules", &value))
548-
recurse_submodules = parse_push_recurse_submodules_arg(k, value);
543+
recurse_submodules = parse_push_recurse_submodules_arg(k, v);
549544
} else if (!strcmp(k, "submodule.recurse")) {
550545
int val = git_config_bool(k, v) ?
551546
RECURSE_SUBMODULES_ON_DEMAND : RECURSE_SUBMODULES_OFF;

builtin/send-pack.c

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -135,21 +135,18 @@ static int send_pack_config(const char *k, const char *v,
135135
const struct config_context *ctx, void *cb)
136136
{
137137
if (!strcmp(k, "push.gpgsign")) {
138-
const char *value;
139-
if (!git_config_get_value("push.gpgsign", &value)) {
140-
switch (git_parse_maybe_bool(value)) {
141-
case 0:
142-
args.push_cert = SEND_PACK_PUSH_CERT_NEVER;
143-
break;
144-
case 1:
145-
args.push_cert = SEND_PACK_PUSH_CERT_ALWAYS;
146-
break;
147-
default:
148-
if (value && !strcasecmp(value, "if-asked"))
149-
args.push_cert = SEND_PACK_PUSH_CERT_IF_ASKED;
150-
else
151-
return error(_("invalid value for '%s'"), k);
152-
}
138+
switch (git_parse_maybe_bool(v)) {
139+
case 0:
140+
args.push_cert = SEND_PACK_PUSH_CERT_NEVER;
141+
break;
142+
case 1:
143+
args.push_cert = SEND_PACK_PUSH_CERT_ALWAYS;
144+
break;
145+
default:
146+
if (!strcasecmp(v, "if-asked"))
147+
args.push_cert = SEND_PACK_PUSH_CERT_IF_ASKED;
148+
else
149+
return error(_("invalid value for '%s'"), k);
153150
}
154151
}
155152
return git_default_config(k, v, ctx, cb);

config.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1392,6 +1392,9 @@ static int git_default_core_config(const char *var, const char *value,
13921392
check_stat = 1;
13931393
else if (!strcasecmp(value, "minimal"))
13941394
check_stat = 0;
1395+
else
1396+
return error(_("invalid value for '%s': '%s'"),
1397+
var, value);
13951398
}
13961399

13971400
if (!strcmp(var, "core.quotepath")) {
@@ -1548,12 +1551,8 @@ static int git_default_core_config(const char *var, const char *value,
15481551
return 0;
15491552
}
15501553

1551-
if (!strcmp(var, "core.checkroundtripencoding")) {
1552-
if (!value)
1553-
return config_error_nonbool(var);
1554-
check_roundtrip_encoding = xstrdup(value);
1555-
return 0;
1556-
}
1554+
if (!strcmp(var, "core.checkroundtripencoding"))
1555+
return git_config_string(&check_roundtrip_encoding, var, value);
15571556

15581557
if (!strcmp(var, "core.notesref")) {
15591558
if (!value)

convert.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ void convert_attrs(struct index_state *istate,
9292
struct conv_attrs *ca, const char *path);
9393

9494
extern enum eol core_eol;
95-
extern char *check_roundtrip_encoding;
95+
extern const char *check_roundtrip_encoding;
9696
const char *get_cached_convert_stats_ascii(struct index_state *istate,
9797
const char *path);
9898
const char *get_wt_convert_stats_ascii(const char *path);

diff.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -445,9 +445,12 @@ int git_diff_ui_config(const char *var, const char *value,
445445
}
446446

447447
if (!strcmp(var, "diff.algorithm")) {
448+
if (!value)
449+
return config_error_nonbool(var);
448450
diff_algorithm = parse_algorithm_value(value);
449451
if (diff_algorithm < 0)
450-
return -1;
452+
return error(_("unknown value for config '%s': %s"),
453+
var, value);
451454
return 0;
452455
}
453456

@@ -486,7 +489,8 @@ int git_diff_basic_config(const char *var, const char *value,
486489
return config_error_nonbool(var);
487490
val = parse_ws_error_highlight(value);
488491
if (val < 0)
489-
return -1;
492+
return error(_("unknown value for config '%s': %s"),
493+
var, value);
490494
ws_error_highlight_default = val;
491495
return 0;
492496
}

environment.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ const char *excludes_file;
6464
enum auto_crlf auto_crlf = AUTO_CRLF_FALSE;
6565
enum eol core_eol = EOL_UNSET;
6666
int global_conv_flags_eol = CONV_EOL_RNDTRP_WARN;
67-
char *check_roundtrip_encoding = "SHIFT-JIS";
67+
const char *check_roundtrip_encoding = "SHIFT-JIS";
6868
enum branch_track git_branch_track = BRANCH_TRACK_REMOTE;
6969
enum rebase_setup_type autorebase = AUTOREBASE_NEVER;
7070
enum push_default_type push_default = PUSH_DEFAULT_UNSPECIFIED;

gpg-interface.c

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -762,23 +762,14 @@ static int git_gpg_config(const char *var, const char *value,
762762
return 0;
763763
}
764764

765-
if (!strcmp(var, "gpg.ssh.defaultkeycommand")) {
766-
if (!value)
767-
return config_error_nonbool(var);
765+
if (!strcmp(var, "gpg.ssh.defaultkeycommand"))
768766
return git_config_string(&ssh_default_key_command, var, value);
769-
}
770767

771-
if (!strcmp(var, "gpg.ssh.allowedsignersfile")) {
772-
if (!value)
773-
return config_error_nonbool(var);
768+
if (!strcmp(var, "gpg.ssh.allowedsignersfile"))
774769
return git_config_pathname(&ssh_allowed_signers, var, value);
775-
}
776770

777-
if (!strcmp(var, "gpg.ssh.revocationfile")) {
778-
if (!value)
779-
return config_error_nonbool(var);
771+
if (!strcmp(var, "gpg.ssh.revocationfile"))
780772
return git_config_pathname(&ssh_revocation_file, var, value);
781-
}
782773

783774
if (!strcmp(var, "gpg.program") || !strcmp(var, "gpg.openpgp.program"))
784775
fmtname = "openpgp";

imap-send.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1346,7 +1346,7 @@ static int git_imap_config(const char *var, const char *val,
13461346
server.port = git_config_int(var, val, ctx->kvi);
13471347
else if (!strcmp("imap.host", var)) {
13481348
if (!val) {
1349-
git_die_config("imap.host", "Missing value for 'imap.host'");
1349+
return config_error_nonbool(var);
13501350
} else {
13511351
if (starts_with(val, "imap:"))
13521352
val += 5;

merge-ll.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ static int read_merge_config(const char *var, const char *value,
301301

302302
if (!strcmp("driver", key)) {
303303
if (!value)
304-
return error("%s: lacks value", var);
304+
return config_error_nonbool(var);
305305
/*
306306
* merge.<name>.driver specifies the command line:
307307
*

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")) {

xdiff-interface.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "git-compat-util.h"
2+
#include "gettext.h"
23
#include "config.h"
34
#include "hex.h"
45
#include "object-store-ll.h"
@@ -313,7 +314,7 @@ int git_xmerge_config(const char *var, const char *value,
313314
{
314315
if (!strcmp(var, "merge.conflictstyle")) {
315316
if (!value)
316-
die("'%s' is not a boolean", var);
317+
return config_error_nonbool(var);
317318
if (!strcmp(value, "diff3"))
318319
git_xmerge_style = XDL_MERGE_DIFF3;
319320
else if (!strcmp(value, "zdiff3"))
@@ -325,8 +326,8 @@ int git_xmerge_config(const char *var, const char *value,
325326
* git-completion.bash when you add new merge config
326327
*/
327328
else
328-
die("unknown style '%s' given for '%s'",
329-
value, var);
329+
return error(_("unknown style '%s' given for '%s'"),
330+
value, var);
330331
return 0;
331332
}
332333
return git_default_config(var, value, ctx, cb);

0 commit comments

Comments
 (0)