config: use git_config_string() for core.checkRoundTripEncoding

Since this code path was recently converted to check for a NULL value, it now behaves exactly like git_config_string(). We can shorten the code a bit by using that helper. Note that git_config_string() takes a const pointer, but our storage variable is non-const. We're better off making this "const", though, since the default value points to a string literal (and thus it would be an error if anybody tried to write to it). 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 be6bc048d74779476610caa7bfb51ef0b71ba5a6
3 files changed +4 -8
config.c
+2 -6
@@ -1551,12 +1551,8 @@ static int git_default_core_config(const char *var, const char *value,
1551 return 0;
1552 }
1553
1554 - if (!strcmp(var, "core.checkroundtripencoding")) {
1555 - if (!value)
1556 - return config_error_nonbool(var);
1557 - check_roundtrip_encoding = xstrdup(value);
1558 - return 0;
1559 - }
1554 + if (!strcmp(var, "core.checkroundtripencoding"))
1555 + return git_config_string(&check_roundtrip_encoding, var, value);
1556
1557 if (!strcmp(var, "core.notesref")) {
1558 if (!value)
convert.h
+1 -1
@@ -92,7 +92,7 @@ void convert_attrs(struct index_state *istate,
92 struct conv_attrs *ca, const char *path);
93
94 extern enum eol core_eol;
95 -extern char *check_roundtrip_encoding;
95 +extern const char *check_roundtrip_encoding;
96 const char *get_cached_convert_stats_ascii(struct index_state *istate,
97 const char *path);
98 const char *get_wt_convert_stats_ascii(const char *path);
environment.c
+1 -1
@@ -64,7 +64,7 @@ const char *excludes_file;
64 enum auto_crlf auto_crlf = AUTO_CRLF_FALSE;
65 enum eol core_eol = EOL_UNSET;
66 int global_conv_flags_eol = CONV_EOL_RNDTRP_WARN;
67 -char *check_roundtrip_encoding = "SHIFT-JIS";
67 +const char *check_roundtrip_encoding = "SHIFT-JIS";
68 enum branch_track git_branch_track = BRANCH_TRACK_REMOTE;
69 enum rebase_setup_type autorebase = AUTOREBASE_NEVER;
70 enum push_default_type push_default = PUSH_DEFAULT_UNSPECIFIED;