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

[Outreachy PATCH] environment: move commit_encoding into repo_config_values

From
OAOkhuomon Ajayi <okhuomonajayi54@gmail.com>
Date
Oct 21, 2026, 15:56 UTC
Message-ID
<20261021155608.58509-1-okhuomonajayi54@gmail.com>

Move i18n.commitEncoding from the global git_commit_encoding variable into struct repo_config_values.

Initialize and release the value with the other repository config values.

Pass the repository to write_commit_tree().
Signed-off-by: Okhuomon Ajayi <okhuomonajayi54@gmail.com>
---
 commit.c      | 16 ++++++++++------
 environment.c | 15 +++++++++++----
 environment.h |  4 +++-
 3 files changed, 24 insertions(+), 11 deletions(-)
diff --git a/commit.c b/commit.c
index ad26f0b40a..91287289f4 100644
--- a/commit.c
+++ b/commit.c
@@ -1683,7 +1683,8 @@ N_("Warning: commit message did not conform to UTF-8.\n"
    "You may want to amend it after fixing the message, or set the config\n"
    "variable i18n.commitEncoding to the encoding your project uses.\n");
 
-static void write_commit_tree(struct strbuf *buffer, const char *msg, size_t msg_len,
+static void write_commit_tree(struct repository *r,
+			      struct strbuf *buffer, const char *msg, size_t msg_len,
 			      const struct object_id *tree,
 			      const struct object_id *parents, size_t parents_len,
 			      const char *author, const char *committer,
@@ -1691,9 +1692,10 @@ static void write_commit_tree(struct strbuf *buffer, const char *msg, size_t msg
 {
 	int encoding_is_utf8;
 	size_t i;
+	const char *encoding = repo_config_values(r)->commit_encoding;
 
 	/* Not having i18n.commitencoding is the same as having utf-8 */
-	encoding_is_utf8 = is_encoding_utf8(git_commit_encoding);
+	encoding_is_utf8 = is_encoding_utf8(encoding);
 
 	strbuf_grow(buffer, 8192); /* should avoid reallocs for the headers */
 	strbuf_addf(buffer, "tree %s\n", oid_to_hex(tree));
@@ -1714,7 +1716,7 @@ static void write_commit_tree(struct strbuf *buffer, const char *msg, size_t msg
 		committer = git_committer_info(IDENT_STRICT);
 	strbuf_addf(buffer, "committer %s\n", committer);
 	if (!encoding_is_utf8)
-		strbuf_addf(buffer, "encoding %s\n", git_commit_encoding);
+		strbuf_addf(buffer, "encoding %s\n", encoding);
 
 	while (extra) {
 		add_extra_header(buffer, extra);
@@ -1734,6 +1736,7 @@ int commit_tree_extended(const char *msg, size_t msg_len,
 			 const struct commit_extra_header *extra)
 {
 	struct repository *r = the_repository;
+	const char *encoding = repo_config_values(r)->commit_encoding;
 	int result = 0;
 	int encoding_is_utf8;
 	bool warned = false;
@@ -1744,7 +1747,7 @@ int commit_tree_extended(const char *msg, size_t msg_len,
 	size_t i, nparents;
 
 	/* Not having i18n.commitencoding is the same as having utf-8 */
-	encoding_is_utf8 = is_encoding_utf8(git_commit_encoding);
+	encoding_is_utf8 = is_encoding_utf8(encoding);
 
 	odb_assert_oid_type(the_repository->objects, tree, OBJ_TREE);
 
@@ -1757,7 +1760,8 @@ int commit_tree_extended(const char *msg, size_t msg_len,
 	for (const struct commit_list *p = parents; p; p = p->next)
 		oidcpy(&parent_buf[i++], &p->item->object.oid);
 
-	write_commit_tree(&buffer, msg, msg_len, tree, parent_buf, nparents, author, committer, extra);
+	write_commit_tree(r, &buffer, msg, msg_len, tree, parent_buf,
+			  nparents, author, committer, extra);
 
 	/* And check the encoding. */
 	if (encoding_is_utf8 && !ensure_utf8(&buffer)) {
@@ -1793,7 +1797,7 @@ int commit_tree_extended(const char *msg, size_t msg_len,
 			free(mapped_parents);
 			goto out;
 		}
-		write_commit_tree(&compat_buffer, msg, msg_len, &mapped_tree,
+		write_commit_tree(r, &compat_buffer, msg, msg_len, &mapped_tree,
 				  mapped_parents, nparents, author, committer, compat_extra);
 		free_commit_extra_headers(compat_extra);
 		free(mapped_parents);
diff --git a/environment.c b/environment.c
index c83cf44839..632fbfad55 100644
--- a/environment.c
+++ b/environment.c
@@ -43,7 +43,6 @@ static int zlib_compression_seen;
 
 int minimum_abbrev = 4, default_abbrev = -1;
 int assume_unchanged;
-char *git_commit_encoding;
 char *git_log_output_encoding;
 int fsync_object_files = -1;
 int use_fsync = -1;
@@ -222,7 +221,9 @@ const char *get_log_output_encoding(void)
 
 const char *get_commit_output_encoding(void)
 {
-	return git_commit_encoding ? git_commit_encoding : "UTF-8";
+	struct repo_config_values *cfg = repo_config_values(the_repository);
+
+	return cfg->commit_encoding ? cfg->commit_encoding : "UTF-8";
 }
 
 int use_optional_locks(void)
@@ -597,9 +598,11 @@ static int git_default_sparse_config(const char *var, const char *value)
 
 static int git_default_i18n_config(const char *var, const char *value)
 {
+	struct repo_config_values *cfg = repo_config_values(the_repository);
+
 	if (!strcmp(var, "i18n.commitencoding")) {
-		FREE_AND_NULL(git_commit_encoding);
-		return git_config_string(&git_commit_encoding, var, value);
+		FREE_AND_NULL(cfg->commit_encoding);
+		return git_config_string(&cfg->commit_encoding, var, value);
 	}
 
 	if (!strcmp(var, "i18n.logoutputencoding")) {
@@ -783,6 +786,9 @@ void repo_config_values_init(struct repo_config_values *cfg)
 
 	/* section "branch" config values */
 	cfg->branch_track = BRANCH_TRACK_REMOTE;
+
+	/* section "i18n" config values */
+	cfg->commit_encoding = NULL;
 }
 
 void repo_config_values_clear(struct repo_config_values *cfg)
@@ -794,4 +800,5 @@ void repo_config_values_clear(struct repo_config_values *cfg)
 	FREE_AND_NULL(cfg->askpass_program);
 	FREE_AND_NULL(cfg->apply_default_whitespace);
 	FREE_AND_NULL(cfg->apply_default_ignorewhitespace);
+	FREE_AND_NULL(cfg->commit_encoding);
 }
diff --git a/environment.h b/environment.h
index b336459e90..5b9c445146 100644
--- a/environment.h
+++ b/environment.h
@@ -147,6 +147,9 @@ struct repo_config_values {
 
 	/* section "branch" config values */
 	enum branch_track branch_track;
+
+	/* section "i18n" config values */
+	char *commit_encoding;
 };
 
 struct repo_config_values *repo_config_values(struct repository *repo);
@@ -242,7 +245,6 @@ extern int grafts_keep_true_parents;
 const char *get_log_output_encoding(void);
 const char *get_commit_output_encoding(void);
 
-extern char *git_commit_encoding;
 extern char *git_log_output_encoding;
 
 /*

base-commit: 47fdf2208c5b94c8cc01c106b8f7c85efb91c926
-- 
2.54.0
Next: Junio C Hamano
Message 1 of 3 in “environment: move commit_encoding into repo_config_values”
  1. environment: move commit_encoding into repo_config_valuesOkhuomon Ajayi, Oct 21, 2026
  2. Junio C HamanoOct 21, 2026
  3. Okhuomon AjayiOct 21, 2026

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.