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

[PATCH/RFC 2/2] format-patch: produce non colorized patches when ui.color=always

From
Pang Yan Han <pangyanhan@gmail.com>
Date
Sep 12, 2011, 15:56 UTC
Message-ID
<1315843016-10959-3-git-send-email-pangyanhan@gmail.com>
In-Reply-To
<1315843016-10959-1-git-send-email-pangyanhan@gmail.com>

commit c9bfb953 (want_color: automatically fallback to color.ui) introduced a regression where format-patch produces colorized patches when color.ui is set to "always".

Teach format-patch to disable colorized output by introducing the color_disable function in color.c

Signed-off-by: Pang Yan Han <pangyanhan@gmail.com>
---
 builtin/log.c                 |    1 +
 color.c                       |    5 +++++
 color.h                       |    1 +
 t/t4051-format-patch-color.sh |    2 +-
 4 files changed, 8 insertions(+), 1 deletions(-)
diff --git a/builtin/log.c b/builtin/log.c
index d760ee0..f62520d 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -1090,6 +1090,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
 	extra_to.strdup_strings = 1;
 	extra_cc.strdup_strings = 1;
 	git_config(git_format_config, NULL);
+	color_disable();
 	init_revisions(&rev, prefix);
 	rev.commit_format = CMIT_FMT_EMAIL;
 	rev.verbose_header = 1;
diff --git a/color.c b/color.c
index e8e2681..48e7208 100644
--- a/color.c
+++ b/color.c
@@ -207,6 +207,11 @@ int want_color(int var)
 	return var;
 }
 
+void color_disable(void)
+{
+	git_use_color_default = 0;
+}
+
 int git_color_config(const char *var, const char *value, void *cb)
 {
 	if (!strcmp(var, "color.ui")) {
diff --git a/color.h b/color.h
index 9a8495b..ff4e6e5 100644
--- a/color.h
+++ b/color.h
@@ -77,6 +77,7 @@ int git_color_default_config(const char *var, const char *value, void *cb);
 
 int git_config_colorbool(const char *var, const char *value);
 int want_color(int var);
+void color_disable(void);
 void color_parse(const char *value, const char *var, char *dst);
 void color_parse_mem(const char *value, int len, const char *var, char *dst);
 __attribute__((format (printf, 3, 4)))
diff --git a/t/t4051-format-patch-color.sh b/t/t4051-format-patch-color.sh
index db30840..44dba16 100755
--- a/t/t4051-format-patch-color.sh
+++ b/t/t4051-format-patch-color.sh
@@ -13,7 +13,7 @@ test_expect_success setup '
 	git commit -m "commit2"
 '
 
-test_expect_failure 'format patch with ui.color=always generates non colorized patch' '
+test_expect_success 'format patch with ui.color=always generates non colorized patch' '
 	git config color.ui always &&
 	git format-patch -1 &&
 	mv 0001-commit2.patch actual &&
-- 
1.7.7.rc0.190.g816e
Previous: Jeff KingNext: Jeff King
Message 4 of 5 in “format-patch: produce non colorized patches when color.ui=always”
  1. 0/2 format-patch: produce non colorized patches when color.ui=alwaysPang Yan Han, Sep 12, 2011
  2. 1/2 format-patch: demonstrate that color.ui=always produces colorized patchesPang Yan Han, Sep 12, 2011
  3. Jeff KingSep 12, 2011
  4. 2/2 format-patch: produce non colorized patches when ui.color=alwaysPang Yan Han, Sep 12, 2011
  5. Jeff KingSep 12, 2011

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.