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

[PATCH 2/3] don't write to git_log_output_encoding outside git_config()

From
Matthieu Moy <matthieu.moy@imag.fr>
Date
Aug 30, 2010, 23:15 UTC
Message-ID
<1283210123-19752-2-git-send-email-Matthieu.Moy@imag.fr>
In-Reply-To
<vpqhbibbthi.fsf@bauges.imag.fr>

The log encoding can be given by the user either with --encoding=foo or with i18n.logoutputencoding. The code dealing with this used to write to git_log_output_encoding in both places, making sure that --encoding=foo is dealt with after reading the configuration file.

This is a very fragile mechanism, since any further call to git_config(git_default_config, ...) the value given on the command line.

Instead, keep the config value and the cli value, and decide which one to take at read time (in the straightforward accessor get_git_log_output_encoding()).

Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>
---
So, this isn't strictly necessary since the new version of the patch
implementing the gitattributes file doesn't read the full config
anymore, but I think that makes the code more robust.
 builtin/log.c |    4 ++--
 cache.h       |   18 ++++++++++++++++++
 environment.c |    4 +++-
 pretty.c      |    4 ++--
 revision.c    |    4 ++--
 5 files changed, 27 insertions(+), 7 deletions(-)
diff --git a/builtin/log.c b/builtin/log.c
index eaa1ee0..f30a6ba 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -329,8 +329,8 @@ static void show_tagger(char *buf, int len, struct rev_info *rev)
 	struct strbuf out = STRBUF_INIT;
 
 	pp_user_info("Tagger", rev->commit_format, &out, buf, rev->date_mode,
-		git_log_output_encoding ?
-		git_log_output_encoding: git_commit_encoding);
+		get_git_log_output_encoding() ?
+		get_git_log_output_encoding(): git_commit_encoding);
 	printf("%s", out.buf);
 	strbuf_release(&out);
 }
diff --git a/cache.h b/cache.h
index eb77e1d..7e10a39 100644
--- a/cache.h
+++ b/cache.h
@@ -1005,7 +1005,25 @@ extern int user_ident_explicitly_given;
 extern int user_ident_sufficiently_given(void);
 
 extern const char *git_commit_encoding;
+
+/* Value found in config file */
 extern const char *git_log_output_encoding;
+
+/* Value given in command line with --encoding */
+extern const char *git_log_output_encoding_cli;
+
+/* 
+ * Prioritize the value given by the command-line over the value found
+ * in the config file.
+ */
+static inline
+const char *get_git_log_output_encoding()
+{
+	return git_log_output_encoding_cli ?
+		git_log_output_encoding_cli :
+		git_log_output_encoding;
+}
+
 extern const char *git_mailmap_file;
 
 /* IO helper functions */
diff --git a/environment.c b/environment.c
index 83d38d3..212f086 100644
--- a/environment.c
+++ b/environment.c
@@ -23,7 +23,9 @@ int log_all_ref_updates = -1; /* unspecified */
 int warn_ambiguous_refs = 1;
 int repository_format_version;
 const char *git_commit_encoding;
-const char *git_log_output_encoding;
+const char *git_log_output_encoding = NULL;
+const char *git_log_output_encoding_cli = NULL;
+
 int shared_repository = PERM_UMASK;
 const char *apply_default_whitespace;
 const char *apply_default_ignorewhitespace;
diff --git a/pretty.c b/pretty.c
index f85444b..4187a50 100644
--- a/pretty.c
+++ b/pretty.c
@@ -1159,8 +1159,8 @@ char *reencode_commit_message(const struct commit *commit, const char **encoding
 {
 	const char *encoding;
 
-	encoding = (git_log_output_encoding
-		    ? git_log_output_encoding
+	encoding = (get_git_log_output_encoding()
+		    ? get_git_log_output_encoding()
 		    : git_commit_encoding);
 	if (!encoding)
 		encoding = "UTF-8";
diff --git a/revision.c b/revision.c
index b1c1890..791c757 100644
--- a/revision.c
+++ b/revision.c
@@ -1402,9 +1402,9 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
 		revs->grep_filter.all_match = 1;
 	} else if ((argcount = parse_long_opt("encoding", argv, &optarg))) {
 		if (strcmp(optarg, "none"))
-			git_log_output_encoding = xstrdup(optarg);
+			git_log_output_encoding_cli = xstrdup(optarg);
 		else
-			git_log_output_encoding = "";
+			git_log_output_encoding_cli = "";
 		return argcount;
 	} else if (!strcmp(arg, "--reverse")) {
 		revs->reverse ^= 1;
-- 
1.7.2.2.175.ga619d.dirty
Previous: Matthieu MoyNext: Matthieu Moy
Message 26 of 36 in “Add global and system-wide gitattributes”
  1. Add global and system-wide gitattributesPetr Onderka, Aug 11, 2010
  2. Henrik GrubbströmAug 11, 2010
  3. Petr OnderkaAug 11, 2010
  4. Matthieu MoyAug 11, 2010
  5. Junio C HamanoAug 11, 2010
  6. Petr OnderkaAug 16, 2010
  7. Add global and system-wide gitattributesPetr Onderka, Aug 16, 2010
  8. Štěpán NěmecAug 25, 2010
  9. Matthieu MoyAug 28, 2010
  10. Junio C HamanoAug 30, 2010
  11. Štěpán NěmecAug 30, 2010
  12. Matthieu MoyAug 28, 2010
  13. core.attributesfile: a fix, a simplification, and a testMatthieu Moy, Aug 28, 2010
  14. Štěpán NěmecAug 29, 2010
  15. Junio C HamanoAug 30, 2010
  16. Matthieu MoyAug 30, 2010
  17. Junio C HamanoAug 30, 2010
  18. Junio C HamanoAug 30, 2010
  19. Matthieu MoyAug 30, 2010
  20. 1/3 tests: factor HOME=$(pwd) in test-lib.shMatthieu Moy, Aug 30, 2010
  21. Ævar Arnfjörð BjarmasonAug 31, 2010
  22. Ævar Arnfjörð BjarmasonSep 1, 2010
  23. Junio C HamanoSep 1, 2010
  24. Ævar Arnfjörð BjarmasonSep 1, 2010
  25. Matthieu MoySep 1, 2010
  26. 2/3 don't write to git_log_output_encoding outside git_config()Matthieu Moy, Aug 30, 2010
  27. Matthieu MoySep 2, 2010
  28. Junio C HamanoSep 2, 2010
  29. 3/3 Add global and system-wide gitattributesMatthieu Moy, Aug 30, 2010
  30. Matthieu MoyAug 31, 2010
  31. Add global and system-wide gitattributesMatthieu Moy, Aug 31, 2010
  32. Junio C HamanoAug 31, 2010
  33. tests: factor HOME=$(pwd) in test-lib.shMatthieu Moy, Aug 30, 2010
  34. Ævar Arnfjörð BjarmasonAug 30, 2010
  35. Matthieu MoyAug 30, 2010
  36. Ævar Arnfjörð BjarmasonAug 30, 2010

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.