Skip to content

Commit

Permalink
Merge branch 'jk/config-cleanup'
Browse files Browse the repository at this point in the history
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
  • Loading branch information
gitster committed Dec 20, 2023
2 parents 2b9cbc6 + ea8f949 commit 66e959f
Show file tree
Hide file tree
Showing 11 changed files with 55 additions and 73 deletions.
31 changes: 13 additions & 18 deletions builtin/push.c
Original file line number Diff line number Diff line change
Expand Up @@ -526,26 +526,21 @@ static int git_push_config(const char *k, const char *v,
*flags |= TRANSPORT_PUSH_AUTO_UPSTREAM;
return 0;
} else if (!strcmp(k, "push.gpgsign")) {
const char *value;
if (!git_config_get_value("push.gpgsign", &value)) {
switch (git_parse_maybe_bool(value)) {
case 0:
set_push_cert_flags(flags, SEND_PACK_PUSH_CERT_NEVER);
break;
case 1:
set_push_cert_flags(flags, SEND_PACK_PUSH_CERT_ALWAYS);
break;
default:
if (value && !strcasecmp(value, "if-asked"))
set_push_cert_flags(flags, SEND_PACK_PUSH_CERT_IF_ASKED);
else
return error(_("invalid value for '%s'"), k);
}
switch (git_parse_maybe_bool(v)) {
case 0:
set_push_cert_flags(flags, SEND_PACK_PUSH_CERT_NEVER);
break;
case 1:
set_push_cert_flags(flags, SEND_PACK_PUSH_CERT_ALWAYS);
break;
default:
if (!strcasecmp(v, "if-asked"))
set_push_cert_flags(flags, SEND_PACK_PUSH_CERT_IF_ASKED);
else
return error(_("invalid value for '%s'"), k);
}
} else if (!strcmp(k, "push.recursesubmodules")) {
const char *value;
if (!git_config_get_value("push.recursesubmodules", &value))
recurse_submodules = parse_push_recurse_submodules_arg(k, value);
recurse_submodules = parse_push_recurse_submodules_arg(k, v);
} else if (!strcmp(k, "submodule.recurse")) {
int val = git_config_bool(k, v) ?
RECURSE_SUBMODULES_ON_DEMAND : RECURSE_SUBMODULES_OFF;
Expand Down
27 changes: 12 additions & 15 deletions builtin/send-pack.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,21 +135,18 @@ static int send_pack_config(const char *k, const char *v,
const struct config_context *ctx, void *cb)
{
if (!strcmp(k, "push.gpgsign")) {
const char *value;
if (!git_config_get_value("push.gpgsign", &value)) {
switch (git_parse_maybe_bool(value)) {
case 0:
args.push_cert = SEND_PACK_PUSH_CERT_NEVER;
break;
case 1:
args.push_cert = SEND_PACK_PUSH_CERT_ALWAYS;
break;
default:
if (value && !strcasecmp(value, "if-asked"))
args.push_cert = SEND_PACK_PUSH_CERT_IF_ASKED;
else
return error(_("invalid value for '%s'"), k);
}
switch (git_parse_maybe_bool(v)) {
case 0:
args.push_cert = SEND_PACK_PUSH_CERT_NEVER;
break;
case 1:
args.push_cert = SEND_PACK_PUSH_CERT_ALWAYS;
break;
default:
if (!strcasecmp(v, "if-asked"))
args.push_cert = SEND_PACK_PUSH_CERT_IF_ASKED;
else
return error(_("invalid value for '%s'"), k);
}
}
return git_default_config(k, v, ctx, cb);
Expand Down
11 changes: 5 additions & 6 deletions config.c
Original file line number Diff line number Diff line change
Expand Up @@ -1392,6 +1392,9 @@ static int git_default_core_config(const char *var, const char *value,
check_stat = 1;
else if (!strcasecmp(value, "minimal"))
check_stat = 0;
else
return error(_("invalid value for '%s': '%s'"),
var, value);
}

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

if (!strcmp(var, "core.checkroundtripencoding")) {
if (!value)
return config_error_nonbool(var);
check_roundtrip_encoding = xstrdup(value);
return 0;
}
if (!strcmp(var, "core.checkroundtripencoding"))
return git_config_string(&check_roundtrip_encoding, var, value);

if (!strcmp(var, "core.notesref")) {
if (!value)
Expand Down
2 changes: 1 addition & 1 deletion convert.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ void convert_attrs(struct index_state *istate,
struct conv_attrs *ca, const char *path);

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 *path);
const char *get_wt_convert_stats_ascii(const char *path);
Expand Down
8 changes: 6 additions & 2 deletions diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -445,9 +445,12 @@ int git_diff_ui_config(const char *var, const char *value,
}

if (!strcmp(var, "diff.algorithm")) {
if (!value)
return config_error_nonbool(var);
diff_algorithm = parse_algorithm_value(value);
if (diff_algorithm < 0)
return -1;
return error(_("unknown value for config '%s': %s"),
var, value);
return 0;
}

Expand Down Expand Up @@ -486,7 +489,8 @@ int git_diff_basic_config(const char *var, const char *value,
return config_error_nonbool(var);
val = parse_ws_error_highlight(value);
if (val < 0)
return -1;
return error(_("unknown value for config '%s': %s"),
var, value);
ws_error_highlight_default = val;
return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion environment.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const char *excludes_file;
enum auto_crlf auto_crlf = AUTO_CRLF_FALSE;
enum eol core_eol = EOL_UNSET;
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 rebase_setup_type autorebase = AUTOREBASE_NEVER;
enum push_default_type push_default = PUSH_DEFAULT_UNSPECIFIED;
Expand Down
15 changes: 3 additions & 12 deletions gpg-interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -762,23 +762,14 @@ static int git_gpg_config(const char *var, const char *value,
return 0;
}

if (!strcmp(var, "gpg.ssh.defaultkeycommand")) {
if (!value)
return config_error_nonbool(var);
if (!strcmp(var, "gpg.ssh.defaultkeycommand"))
return git_config_string(&ssh_default_key_command, var, value);
}

if (!strcmp(var, "gpg.ssh.allowedsignersfile")) {
if (!value)
return config_error_nonbool(var);
if (!strcmp(var, "gpg.ssh.allowedsignersfile"))
return git_config_pathname(&ssh_allowed_signers, var, value);
}

if (!strcmp(var, "gpg.ssh.revocationfile")) {
if (!value)
return config_error_nonbool(var);
if (!strcmp(var, "gpg.ssh.revocationfile"))
return git_config_pathname(&ssh_revocation_file, var, value);
}

if (!strcmp(var, "gpg.program") || !strcmp(var, "gpg.openpgp.program"))
fmtname = "openpgp";
Expand Down
2 changes: 1 addition & 1 deletion imap-send.c
Original file line number Diff line number Diff line change
Expand Up @@ -1346,7 +1346,7 @@ static int git_imap_config(const char *var, const char *val,
server.port = git_config_int(var, val, ctx->kvi);
else if (!strcmp("imap.host", var)) {
if (!val) {
git_die_config("imap.host", "Missing value for 'imap.host'");
return config_error_nonbool(var);
} else {
if (starts_with(val, "imap:"))
val += 5;
Expand Down
2 changes: 1 addition & 1 deletion merge-ll.c
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ static int read_merge_config(const char *var, const char *value,

if (!strcmp("driver", key)) {
if (!value)
return error("%s: lacks value", var);
return config_error_nonbool(var);
/*
* merge.<name>.driver specifies the command line:
*
Expand Down
21 changes: 8 additions & 13 deletions sequencer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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")) {
Expand Down
7 changes: 4 additions & 3 deletions xdiff-interface.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "git-compat-util.h"
#include "gettext.h"
#include "config.h"
#include "hex.h"
#include "object-store-ll.h"
Expand Down Expand Up @@ -313,7 +314,7 @@ int git_xmerge_config(const char *var, const char *value,
{
if (!strcmp(var, "merge.conflictstyle")) {
if (!value)
die("'%s' is not a boolean", var);
return config_error_nonbool(var);
if (!strcmp(value, "diff3"))
git_xmerge_style = XDL_MERGE_DIFF3;
else if (!strcmp(value, "zdiff3"))
Expand All @@ -325,8 +326,8 @@ int git_xmerge_config(const char *var, const char *value,
* git-completion.bash when you add new merge config
*/
else
die("unknown style '%s' given for '%s'",
value, var);
return error(_("unknown style '%s' given for '%s'"),
value, var);
return 0;
}
return git_default_config(var, value, ctx, cb);
Expand Down

0 comments on commit 66e959f

Please sign in to comment.