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

[PATCH v4 3/4] git mailinfo: added a --recode-patch parameter

From
ZHANG, Le <r0bertz@gentoo.org>
Date
Nov 28, 2010, 19:10 UTC
Message-ID
<1290971417-4474-4-git-send-email-r0bertz@gentoo.org>
In-Reply-To
<1290971417-4474-1-git-send-email-r0bertz@gentoo.org>

When this parameter is specified, patch will be converted to a target encoding before applied. The target encoding defaults to UTF-8. It could also be specified by i18n.patchencoding.

Signed-off-by: ZHANG, Le <r0bertz@gentoo.org>
---
 Documentation/git-mailinfo.txt |    6 +++++-
 builtin/mailinfo.c             |   11 +++++++++--
 2 files changed, 14 insertions(+), 3 deletions(-)
diff --git a/Documentation/git-mailinfo.txt b/Documentation/git-mailinfo.txt
index 3ea5aad..3e84817 100644
--- a/Documentation/git-mailinfo.txt
+++ b/Documentation/git-mailinfo.txt
@@ -45,7 +45,7 @@ OPTIONS
 	them.  This used to be optional but now it is the default.
 +
 Note that the patch is always used as-is without charset
-conversion, even with this flag.
+conversion, even with this flag; use '--recode-patch' for that.
 
 --encoding=<encoding>::
 	Similar to -u.  But when re-coding, the charset specified here is
@@ -54,6 +54,10 @@ conversion, even with this flag.
 -n::
 	Disable all charset re-coding of the metadata.
 
+--recode-patch::
+	Convert the patch from the e-mail to UTF-8 (or the value of the
+	configuration variable i18n.patchencoding if it is set).
+
 --scissors::
 	Remove everything in body before a scissors line.  A line that
 	mainly consists of scissors (either ">8" or "8<") and perforation
diff --git a/builtin/mailinfo.c b/builtin/mailinfo.c
index 1406d9f..96181e6 100644
--- a/builtin/mailinfo.c
+++ b/builtin/mailinfo.c
@@ -12,6 +12,8 @@ static FILE *cmitmsg, *patchfile, *fin, *fout;
 static int keep_subject;
 static int keep_non_patch_brackets_in_subject;
 static const char *metainfo_charset;
+static const char *patch_charset;
+static int recode_patch;
 static struct strbuf line = STRBUF_INIT;
 static struct strbuf name = STRBUF_INIT;
 static struct strbuf email = STRBUF_INIT;
@@ -828,8 +830,10 @@ static int handle_commit_msg(struct strbuf *line)
 	return 0;
 }
 
-static void handle_patch(const struct strbuf *line)
+static void handle_patch(struct strbuf *line)
 {
+	if (recode_patch)
+		convert_to_utf8(line, charset.buf, patch_charset);
 	fwrite(line->buf, 1, line->len, patchfile);
 	patch_lines++;
 }
@@ -1021,7 +1025,7 @@ static int git_mailinfo_config(const char *var, const char *value, void *unused)
 }
 
 static const char mailinfo_usage[] =
-	"git mailinfo [-k|-b] [-u | --encoding=<encoding> | -n] [--scissors | --no-scissors] msg patch < mail >info";
+	"git mailinfo [-k|-b] [-u | --encoding=<encoding> | -n] [--recode-patch] [--scissors | --no-scissors] msg patch < mail >info";
 
 int cmd_mailinfo(int argc, const char **argv, const char *prefix)
 {
@@ -1034,6 +1038,7 @@ int cmd_mailinfo(int argc, const char **argv, const char *prefix)
 
 	def_charset = (git_commit_encoding ? git_commit_encoding : "UTF-8");
 	metainfo_charset = def_charset;
+	patch_charset = git_patch_encoding ? git_patch_encoding : "UTF-8";
 
 	while (1 < argc && argv[1][0] == '-') {
 		if (!strcmp(argv[1], "-k"))
@@ -1046,6 +1051,8 @@ int cmd_mailinfo(int argc, const char **argv, const char *prefix)
 			metainfo_charset = NULL;
 		else if (!prefixcmp(argv[1], "--encoding="))
 			metainfo_charset = argv[1] + 11;
+		else if (!prefixcmp(argv[1], "--recode-patch"))
+			recode_patch = 1;
 		else if (!strcmp(argv[1], "--scissors"))
 			use_scissors = 1;
 		else if (!strcmp(argv[1], "--no-scissors"))
-- 
1.7.3.2.344.gb3680.dirty
Previous: Junio C HamanoNext: Junio C Hamano
Message 7 of 9 in “add --recode-patch parameter to mailinfo and am”
  1. 0/4 add --recode-patch parameter to mailinfo and amZHANG, Le, Nov 28, 2010
  2. 1/4 mailinfo.c: convert_to_utf8(): added a target_charset parameterZHANG, Le, Nov 28, 2010
  3. Junio C HamanoNov 29, 2010
  4. ZHANG, LeApr 16, 2011
  5. 2/4 i18n.patchencoding: introduce a new config variableZHANG, Le, Nov 28, 2010
  6. Junio C HamanoNov 29, 2010
  7. 3/4 git mailinfo: added a --recode-patch parameterZHANG, Le, Nov 28, 2010
  8. Junio C HamanoNov 29, 2010
  9. 4/4 git am: added a --recode-patch parameterZHANG, Le, Nov 28, 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.