{"thread":{"id":"66623","subject":"[Outreachy PATCH] environment: move commit_encoding into repo_config_values","startedAt":"2026-10-21T15:56:08Z","lastAt":"2026-10-21T21:20:56Z","messageCount":3,"participants":["Okhuomon Ajayi","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"555750","messageId":"20261021155608.58509-1-okhuomonajayi54@gmail.com","threadId":"66623","inReplyTo":null,"subject":"[Outreachy PATCH] environment: move commit_encoding into repo_config_values","fromName":"Okhuomon Ajayi","fromEmail":"okhuomonajayi54@gmail.com","sentAt":"2026-10-21T15:56:08Z","receivedAt":"2026-10-21T15:56:08Z","isPatch":true,"sender":{"key":"okhuomonajayi54@gmail.com","avatar":null},"body":"Move i18n.commitEncoding from the global git_commit_encoding variable\ninto struct repo_config_values.\n\nInitialize and release the value with the other repository config\nvalues.\n\nPass the repository to write_commit_tree().\n\nSigned-off-by: Okhuomon Ajayi <okhuomonajayi54@gmail.com>\n---\n commit.c      | 16 ++++++++++------\n environment.c | 15 +++++++++++----\n environment.h |  4 +++-\n 3 files changed, 24 insertions(+), 11 deletions(-)\n\ndiff --git a/commit.c b/commit.c\nindex ad26f0b40a..91287289f4 100644\n--- a/commit.c\n+++ b/commit.c\n@@ -1683,7 +1683,8 @@ N_(\"Warning: commit message did not conform to UTF-8.\\n\"\n    \"You may want to amend it after fixing the message, or set the config\\n\"\n    \"variable i18n.commitEncoding to the encoding your project uses.\\n\");\n \n-static void write_commit_tree(struct strbuf *buffer, const char *msg, size_t msg_len,\n+static void write_commit_tree(struct repository *r,\n+\t\t\t      struct strbuf *buffer, const char *msg, size_t msg_len,\n \t\t\t      const struct object_id *tree,\n \t\t\t      const struct object_id *parents, size_t parents_len,\n \t\t\t      const char *author, const char *committer,\n@@ -1691,9 +1692,10 @@ static void write_commit_tree(struct strbuf *buffer, const char *msg, size_t msg\n {\n \tint encoding_is_utf8;\n \tsize_t i;\n+\tconst char *encoding = repo_config_values(r)->commit_encoding;\n \n \t/* Not having i18n.commitencoding is the same as having utf-8 */\n-\tencoding_is_utf8 = is_encoding_utf8(git_commit_encoding);\n+\tencoding_is_utf8 = is_encoding_utf8(encoding);\n \n \tstrbuf_grow(buffer, 8192); /* should avoid reallocs for the headers */\n \tstrbuf_addf(buffer, \"tree %s\\n\", oid_to_hex(tree));\n@@ -1714,7 +1716,7 @@ static void write_commit_tree(struct strbuf *buffer, const char *msg, size_t msg\n \t\tcommitter = git_committer_info(IDENT_STRICT);\n \tstrbuf_addf(buffer, \"committer %s\\n\", committer);\n \tif (!encoding_is_utf8)\n-\t\tstrbuf_addf(buffer, \"encoding %s\\n\", git_commit_encoding);\n+\t\tstrbuf_addf(buffer, \"encoding %s\\n\", encoding);\n \n \twhile (extra) {\n \t\tadd_extra_header(buffer, extra);\n@@ -1734,6 +1736,7 @@ int commit_tree_extended(const char *msg, size_t msg_len,\n \t\t\t const struct commit_extra_header *extra)\n {\n \tstruct repository *r = the_repository;\n+\tconst char *encoding = repo_config_values(r)->commit_encoding;\n \tint result = 0;\n \tint encoding_is_utf8;\n \tbool warned = false;\n@@ -1744,7 +1747,7 @@ int commit_tree_extended(const char *msg, size_t msg_len,\n \tsize_t i, nparents;\n \n \t/* Not having i18n.commitencoding is the same as having utf-8 */\n-\tencoding_is_utf8 = is_encoding_utf8(git_commit_encoding);\n+\tencoding_is_utf8 = is_encoding_utf8(encoding);\n \n \todb_assert_oid_type(the_repository->objects, tree, OBJ_TREE);\n \n@@ -1757,7 +1760,8 @@ int commit_tree_extended(const char *msg, size_t msg_len,\n \tfor (const struct commit_list *p = parents; p; p = p->next)\n \t\toidcpy(&parent_buf[i++], &p->item->object.oid);\n \n-\twrite_commit_tree(&buffer, msg, msg_len, tree, parent_buf, nparents, author, committer, extra);\n+\twrite_commit_tree(r, &buffer, msg, msg_len, tree, parent_buf,\n+\t\t\t  nparents, author, committer, extra);\n \n \t/* And check the encoding. */\n \tif (encoding_is_utf8 && !ensure_utf8(&buffer)) {\n@@ -1793,7 +1797,7 @@ int commit_tree_extended(const char *msg, size_t msg_len,\n \t\t\tfree(mapped_parents);\n \t\t\tgoto out;\n \t\t}\n-\t\twrite_commit_tree(&compat_buffer, msg, msg_len, &mapped_tree,\n+\t\twrite_commit_tree(r, &compat_buffer, msg, msg_len, &mapped_tree,\n \t\t\t\t  mapped_parents, nparents, author, committer, compat_extra);\n \t\tfree_commit_extra_headers(compat_extra);\n \t\tfree(mapped_parents);\ndiff --git a/environment.c b/environment.c\nindex c83cf44839..632fbfad55 100644\n--- a/environment.c\n+++ b/environment.c\n@@ -43,7 +43,6 @@ static int zlib_compression_seen;\n \n int minimum_abbrev = 4, default_abbrev = -1;\n int assume_unchanged;\n-char *git_commit_encoding;\n char *git_log_output_encoding;\n int fsync_object_files = -1;\n int use_fsync = -1;\n@@ -222,7 +221,9 @@ const char *get_log_output_encoding(void)\n \n const char *get_commit_output_encoding(void)\n {\n-\treturn git_commit_encoding ? git_commit_encoding : \"UTF-8\";\n+\tstruct repo_config_values *cfg = repo_config_values(the_repository);\n+\n+\treturn cfg->commit_encoding ? cfg->commit_encoding : \"UTF-8\";\n }\n \n int use_optional_locks(void)\n@@ -597,9 +598,11 @@ static int git_default_sparse_config(const char *var, const char *value)\n \n static int git_default_i18n_config(const char *var, const char *value)\n {\n+\tstruct repo_config_values *cfg = repo_config_values(the_repository);\n+\n \tif (!strcmp(var, \"i18n.commitencoding\")) {\n-\t\tFREE_AND_NULL(git_commit_encoding);\n-\t\treturn git_config_string(&git_commit_encoding, var, value);\n+\t\tFREE_AND_NULL(cfg->commit_encoding);\n+\t\treturn git_config_string(&cfg->commit_encoding, var, value);\n \t}\n \n \tif (!strcmp(var, \"i18n.logoutputencoding\")) {\n@@ -783,6 +786,9 @@ void repo_config_values_init(struct repo_config_values *cfg)\n \n \t/* section \"branch\" config values */\n \tcfg->branch_track = BRANCH_TRACK_REMOTE;\n+\n+\t/* section \"i18n\" config values */\n+\tcfg->commit_encoding = NULL;\n }\n \n void repo_config_values_clear(struct repo_config_values *cfg)\n@@ -794,4 +800,5 @@ void repo_config_values_clear(struct repo_config_values *cfg)\n \tFREE_AND_NULL(cfg->askpass_program);\n \tFREE_AND_NULL(cfg->apply_default_whitespace);\n \tFREE_AND_NULL(cfg->apply_default_ignorewhitespace);\n+\tFREE_AND_NULL(cfg->commit_encoding);\n }\ndiff --git a/environment.h b/environment.h\nindex b336459e90..5b9c445146 100644\n--- a/environment.h\n+++ b/environment.h\n@@ -147,6 +147,9 @@ struct repo_config_values {\n \n \t/* section \"branch\" config values */\n \tenum branch_track branch_track;\n+\n+\t/* section \"i18n\" config values */\n+\tchar *commit_encoding;\n };\n \n struct repo_config_values *repo_config_values(struct repository *repo);\n@@ -242,7 +245,6 @@ extern int grafts_keep_true_parents;\n const char *get_log_output_encoding(void);\n const char *get_commit_output_encoding(void);\n \n-extern char *git_commit_encoding;\n extern char *git_log_output_encoding;\n \n /*\n\nbase-commit: 47fdf2208c5b94c8cc01c106b8f7c85efb91c926\n-- \n2.54.0\n\n\n"},{"id":"555787","messageId":"xmqq33tyn5qi.fsf@gitster.g","threadId":"66623","inReplyTo":"20261021155608.58509-1-okhuomonajayi54@gmail.com","subject":"Re: [Outreachy PATCH] environment: move commit_encoding into repo_config_values","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-10-21T20:44:37Z","receivedAt":"2026-10-21T20:44:37Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Okhuomon Ajayi <okhuomonajayi54@gmail.com> writes:\n\n> Move i18n.commitEncoding from the global git_commit_encoding variable\n> into struct repo_config_values.\n>\n> Initialize and release the value with the other repository config\n> values.\n>\n> Pass the repository to write_commit_tree().\n>\n> Signed-off-by: Okhuomon Ajayi <okhuomonajayi54@gmail.com>\n> ---\n>  commit.c      | 16 ++++++++++------\n>  environment.c | 15 +++++++++++----\n>  environment.h |  4 +++-\n>  3 files changed, 24 insertions(+), 11 deletions(-)\n\nI am not sure if this change makes sense.  The 'git_commit_encoding'\nvariable is declared in 'environment.h' to be globally available and\ndefined in 'environment.c', but its only user is the 'commit.c' file.\n\nI do not think it is worth contaminating the repository configuration\nwith it.  Instead, shouldn't we allow the functions that use this\nglobal to take a \"const char *git_commit_encoding\" parameter (instead\nof a 'repository_config' or a 'repository' structure) and pass it\nthrough?  The callers may need to query the config subsystem to learn\nthe appropriate encoding for the repository they are working with\nbefore calling these functions, but there is no need to pass the\nentire repository structure down the call graph.\n\nThanks.\n\n"},{"id":"555793","messageId":"CAFpMFfCZdz4WLcwJFefXTQ1v_g+mgFQOHxzkf0aZoPqTz3o-=A@mail.gmail.com","threadId":"66623","inReplyTo":"xmqq33tyn5qi.fsf@gitster.g","subject":"Re: [Outreachy PATCH] environment: move commit_encoding into repo_config_values","fromName":"Okhuomon Ajayi","fromEmail":"okhuomonajayi54@gmail.com","sentAt":"2026-10-21T21:20:56Z","receivedAt":"2026-10-21T21:20:56Z","isPatch":true,"sender":{"key":"okhuomonajayi54@gmail.com","avatar":null},"body":"On Wed, Oct 21, 2026 at 9:44 PM Junio C Hamano <gitster@pobox.com> wrote:\n> I do not think it is worth contaminating the repository configuration\n> with it.  Instead, shouldn't we allow the functions that use this\n> global to take a \"const char *git_commit_encoding\" parameter (instead\n> of a 'repository_config' or a 'repository' structure) and pass it\n> through?  The callers may need to query the config subsystem to learn\n> the appropriate encoding for the repository they are working with\n> before calling these functions, but there is no need to pass the\n> entire repository structure down the call graph.\n\nThanks, that makes sense.\n\nSo for v2, write_commit_tree() and commit_tree_extended() would both\ntake the encoding as a \"const char *\" parameter. The callers of\ncommit_tree_extended() would look up i18n.commitEncoding from the\nconfig and pass it in, and commit_tree() would do the same for its\nown callers. Nothing would be added to repo_config_values.\n\nDoes that match what you had in mind?\n\n"}]}