]> git.ipfire.org Git - thirdparty/git.git/commitdiff
config: use git_config_string() for core.checkRoundTripEncoding
authorJeff King <peff@peff.net>
Thu, 7 Dec 2023 07:26:11 +0000 (02:26 -0500)
committerJunio C Hamano <gitster@pobox.com>
Fri, 8 Dec 2023 23:26:22 +0000 (08:26 +0900)
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>
config.c
convert.h
environment.c

index d997c55e33000b3e020a8cd7d49cde46be77c43e..00a11b5d98eded0383d831a749195c256d288f86 100644 (file)
--- a/config.c
+++ b/config.c
@@ -1551,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)
index d925589444b90a11058abe87286df3d5add592f8..ab8b4fa68d67ba3da1fc7900b616dc70a9967eba 100644 (file)
--- a/convert.h
+++ b/convert.h
@@ -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);
index 9e37bf58c0c6822f48152e5ab59c25a0cf39a874..90632a39bc995af8bf56166b4d89bba5d6dd5272 100644 (file)
@@ -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;