git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 6/9] config: use git_config_string() for core.checkRoundTripEncoding

From
Jeff King <peff@peff.net>
Date
Dec 7, 2023, 07:26 UTC
Message-ID
<20231207072611.GF1277973@coredump.intra.peff.net>
In-Reply-To
<20231207072338.GA1277727@coredump.intra.peff.net>

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>
---
An observant reader may notice that this means duplicate config like:
  [core]
  checkRoundTripEncoding = foo
  checkRoundTripEncoding = bar

will leak the string for "foo". That is true before this patch, too, and is true of all callers of git_config_string(). I'm going to punt on that for now, and look into it as a separate series.

 config.c      | 8 ++------
 convert.h     | 2 +-
 environment.c | 2 +-
 3 files changed, 4 insertions(+), 8 deletions(-)
diff --git a/config.c b/config.c
index d997c55e33..00a11b5d98 100644
--- 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)
diff --git a/convert.h b/convert.h
index d925589444..ab8b4fa68d 100644
--- 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);
diff --git a/environment.c b/environment.c
index 9e37bf58c0..90632a39bc 100644
--- a/environment.c
+++ b/environment.c
@@ -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;
-- 
2.43.0.664.ga12c899002
Previous: Jeff KingNext: Jeff King
Message 12 of 16 in “bonus config cleanups”
  1. 0/9 bonus config cleanupsJeff King, Dec 7, 2023
  2. 1/9 config: reject bogus values for core.checkstatJeff King, Dec 7, 2023
  3. Taylor BlauDec 8, 2023
  4. 2/9 git_xmerge_config(): prefer error() to die()Jeff King, Dec 7, 2023
  5. 3/9 imap-send: don't use git_die_config() inside callbackJeff King, Dec 7, 2023
  6. Patrick SteinhardtDec 7, 2023
  7. Taylor BlauDec 8, 2023
  8. Patrick SteinhardtDec 11, 2023
  9. Jeff KingDec 12, 2023
  10. 4/9 config: use config_error_nonbool() instead of custom messagesJeff King, Dec 7, 2023
  11. 5/9 diff: give more detailed messages for bogus diff.* configJeff King, Dec 7, 2023
  12. 6/9 config: use git_config_string() for core.checkRoundTripEncodingJeff King, Dec 7, 2023
  13. 7/9 push: drop confusing configset/callback redundancyJeff King, Dec 7, 2023
  14. 8/9 gpg-interface: drop pointless config_error_nonbool() checksJeff King, Dec 7, 2023
  15. 9/9 sequencer: simplify away extra git_config_string() callJeff King, Dec 7, 2023
  16. Patrick SteinhardtDec 7, 2023

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.