Merge branch 'jk/config-cleanup' into maint-2.43

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
This commit is contained in:
Junio C Hamano
2024-02-08 16:22:07 -08:00
11 changed files with 55 additions and 73 deletions

View File

@ -526,26 +526,21 @@ static int git_push_config(const char *k, const char *v,
*flags |= TRANSPORT_PUSH_AUTO_UPSTREAM; *flags |= TRANSPORT_PUSH_AUTO_UPSTREAM;
return 0; return 0;
} else if (!strcmp(k, "push.gpgsign")) { } else if (!strcmp(k, "push.gpgsign")) {
const char *value; switch (git_parse_maybe_bool(v)) {
if (!git_config_get_value("push.gpgsign", &value)) { case 0:
switch (git_parse_maybe_bool(value)) { set_push_cert_flags(flags, SEND_PACK_PUSH_CERT_NEVER);
case 0: break;
set_push_cert_flags(flags, SEND_PACK_PUSH_CERT_NEVER); case 1:
break; set_push_cert_flags(flags, SEND_PACK_PUSH_CERT_ALWAYS);
case 1: break;
set_push_cert_flags(flags, SEND_PACK_PUSH_CERT_ALWAYS); default:
break; if (!strcasecmp(v, "if-asked"))
default: set_push_cert_flags(flags, SEND_PACK_PUSH_CERT_IF_ASKED);
if (value && !strcasecmp(value, "if-asked")) else
set_push_cert_flags(flags, SEND_PACK_PUSH_CERT_IF_ASKED); return error(_("invalid value for '%s'"), k);
else
return error(_("invalid value for '%s'"), k);
}
} }
} else if (!strcmp(k, "push.recursesubmodules")) { } else if (!strcmp(k, "push.recursesubmodules")) {
const char *value; recurse_submodules = parse_push_recurse_submodules_arg(k, v);
if (!git_config_get_value("push.recursesubmodules", &value))
recurse_submodules = parse_push_recurse_submodules_arg(k, value);
} else if (!strcmp(k, "submodule.recurse")) { } else if (!strcmp(k, "submodule.recurse")) {
int val = git_config_bool(k, v) ? int val = git_config_bool(k, v) ?
RECURSE_SUBMODULES_ON_DEMAND : RECURSE_SUBMODULES_OFF; RECURSE_SUBMODULES_ON_DEMAND : RECURSE_SUBMODULES_OFF;

View File

@ -135,21 +135,18 @@ static int send_pack_config(const char *k, const char *v,
const struct config_context *ctx, void *cb) const struct config_context *ctx, void *cb)
{ {
if (!strcmp(k, "push.gpgsign")) { if (!strcmp(k, "push.gpgsign")) {
const char *value; switch (git_parse_maybe_bool(v)) {
if (!git_config_get_value("push.gpgsign", &value)) { case 0:
switch (git_parse_maybe_bool(value)) { args.push_cert = SEND_PACK_PUSH_CERT_NEVER;
case 0: break;
args.push_cert = SEND_PACK_PUSH_CERT_NEVER; case 1:
break; args.push_cert = SEND_PACK_PUSH_CERT_ALWAYS;
case 1: break;
args.push_cert = SEND_PACK_PUSH_CERT_ALWAYS; default:
break; if (!strcasecmp(v, "if-asked"))
default: args.push_cert = SEND_PACK_PUSH_CERT_IF_ASKED;
if (value && !strcasecmp(value, "if-asked")) else
args.push_cert = SEND_PACK_PUSH_CERT_IF_ASKED; return error(_("invalid value for '%s'"), k);
else
return error(_("invalid value for '%s'"), k);
}
} }
} }
return git_default_config(k, v, ctx, cb); return git_default_config(k, v, ctx, cb);

View File

@ -1392,6 +1392,9 @@ static int git_default_core_config(const char *var, const char *value,
check_stat = 1; check_stat = 1;
else if (!strcasecmp(value, "minimal")) else if (!strcasecmp(value, "minimal"))
check_stat = 0; check_stat = 0;
else
return error(_("invalid value for '%s': '%s'"),
var, value);
} }
if (!strcmp(var, "core.quotepath")) { if (!strcmp(var, "core.quotepath")) {
@ -1548,12 +1551,8 @@ static int git_default_core_config(const char *var, const char *value,
return 0; return 0;
} }
if (!strcmp(var, "core.checkroundtripencoding")) { if (!strcmp(var, "core.checkroundtripencoding"))
if (!value) return git_config_string(&check_roundtrip_encoding, var, value);
return config_error_nonbool(var);
check_roundtrip_encoding = xstrdup(value);
return 0;
}
if (!strcmp(var, "core.notesref")) { if (!strcmp(var, "core.notesref")) {
if (!value) if (!value)

View File

@ -92,7 +92,7 @@ void convert_attrs(struct index_state *istate,
struct conv_attrs *ca, const char *path); struct conv_attrs *ca, const char *path);
extern enum eol core_eol; extern enum eol core_eol;
extern char *check_roundtrip_encoding; extern const char *check_roundtrip_encoding;
const char *get_cached_convert_stats_ascii(struct index_state *istate, const char *get_cached_convert_stats_ascii(struct index_state *istate,
const char *path); const char *path);
const char *get_wt_convert_stats_ascii(const char *path); const char *get_wt_convert_stats_ascii(const char *path);

8
diff.c
View File

@ -445,9 +445,12 @@ int git_diff_ui_config(const char *var, const char *value,
} }
if (!strcmp(var, "diff.algorithm")) { if (!strcmp(var, "diff.algorithm")) {
if (!value)
return config_error_nonbool(var);
diff_algorithm = parse_algorithm_value(value); diff_algorithm = parse_algorithm_value(value);
if (diff_algorithm < 0) if (diff_algorithm < 0)
return -1; return error(_("unknown value for config '%s': %s"),
var, value);
return 0; return 0;
} }
@ -486,7 +489,8 @@ int git_diff_basic_config(const char *var, const char *value,
return config_error_nonbool(var); return config_error_nonbool(var);
val = parse_ws_error_highlight(value); val = parse_ws_error_highlight(value);
if (val < 0) if (val < 0)
return -1; return error(_("unknown value for config '%s': %s"),
var, value);
ws_error_highlight_default = val; ws_error_highlight_default = val;
return 0; return 0;
} }

View File

@ -64,7 +64,7 @@ const char *excludes_file;
enum auto_crlf auto_crlf = AUTO_CRLF_FALSE; enum auto_crlf auto_crlf = AUTO_CRLF_FALSE;
enum eol core_eol = EOL_UNSET; enum eol core_eol = EOL_UNSET;
int global_conv_flags_eol = CONV_EOL_RNDTRP_WARN; int global_conv_flags_eol = CONV_EOL_RNDTRP_WARN;
char *check_roundtrip_encoding = "SHIFT-JIS"; const char *check_roundtrip_encoding = "SHIFT-JIS";
enum branch_track git_branch_track = BRANCH_TRACK_REMOTE; enum branch_track git_branch_track = BRANCH_TRACK_REMOTE;
enum rebase_setup_type autorebase = AUTOREBASE_NEVER; enum rebase_setup_type autorebase = AUTOREBASE_NEVER;
enum push_default_type push_default = PUSH_DEFAULT_UNSPECIFIED; enum push_default_type push_default = PUSH_DEFAULT_UNSPECIFIED;

View File

@ -762,23 +762,14 @@ static int git_gpg_config(const char *var, const char *value,
return 0; return 0;
} }
if (!strcmp(var, "gpg.ssh.defaultkeycommand")) { if (!strcmp(var, "gpg.ssh.defaultkeycommand"))
if (!value)
return config_error_nonbool(var);
return git_config_string(&ssh_default_key_command, var, value); return git_config_string(&ssh_default_key_command, var, value);
}
if (!strcmp(var, "gpg.ssh.allowedsignersfile")) { if (!strcmp(var, "gpg.ssh.allowedsignersfile"))
if (!value)
return config_error_nonbool(var);
return git_config_pathname(&ssh_allowed_signers, var, value); return git_config_pathname(&ssh_allowed_signers, var, value);
}
if (!strcmp(var, "gpg.ssh.revocationfile")) { if (!strcmp(var, "gpg.ssh.revocationfile"))
if (!value)
return config_error_nonbool(var);
return git_config_pathname(&ssh_revocation_file, var, value); return git_config_pathname(&ssh_revocation_file, var, value);
}
if (!strcmp(var, "gpg.program") || !strcmp(var, "gpg.openpgp.program")) if (!strcmp(var, "gpg.program") || !strcmp(var, "gpg.openpgp.program"))
fmtname = "openpgp"; fmtname = "openpgp";

View File

@ -1346,7 +1346,7 @@ static int git_imap_config(const char *var, const char *val,
server.port = git_config_int(var, val, ctx->kvi); server.port = git_config_int(var, val, ctx->kvi);
else if (!strcmp("imap.host", var)) { else if (!strcmp("imap.host", var)) {
if (!val) { if (!val) {
git_die_config("imap.host", "Missing value for 'imap.host'"); return config_error_nonbool(var);
} else { } else {
if (starts_with(val, "imap:")) if (starts_with(val, "imap:"))
val += 5; val += 5;

View File

@ -301,7 +301,7 @@ static int read_merge_config(const char *var, const char *value,
if (!strcmp("driver", key)) { if (!strcmp("driver", key)) {
if (!value) if (!value)
return error("%s: lacks value", var); return config_error_nonbool(var);
/* /*
* merge.<name>.driver specifies the command line: * merge.<name>.driver specifies the command line:
* *

View File

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

View File

@ -1,4 +1,5 @@
#include "git-compat-util.h" #include "git-compat-util.h"
#include "gettext.h"
#include "config.h" #include "config.h"
#include "hex.h" #include "hex.h"
#include "object-store-ll.h" #include "object-store-ll.h"
@ -313,7 +314,7 @@ int git_xmerge_config(const char *var, const char *value,
{ {
if (!strcmp(var, "merge.conflictstyle")) { if (!strcmp(var, "merge.conflictstyle")) {
if (!value) if (!value)
die("'%s' is not a boolean", var); return config_error_nonbool(var);
if (!strcmp(value, "diff3")) if (!strcmp(value, "diff3"))
git_xmerge_style = XDL_MERGE_DIFF3; git_xmerge_style = XDL_MERGE_DIFF3;
else if (!strcmp(value, "zdiff3")) else if (!strcmp(value, "zdiff3"))
@ -325,8 +326,8 @@ int git_xmerge_config(const char *var, const char *value,
* git-completion.bash when you add new merge config * git-completion.bash when you add new merge config
*/ */
else else
die("unknown style '%s' given for '%s'", return error(_("unknown style '%s' given for '%s'"),
value, var); value, var);
return 0; return 0;
} }
return git_default_config(var, value, ctx, cb); return git_default_config(var, value, ctx, cb);