git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 2/2] i18n.repositoryencoding: a new variable specifying the encoding of blobs in the repository
@ 2011-04-16 20:50 ZHANG, Le
  2011-04-19  4:34 ` Junio C Hamano
  0 siblings, 1 reply; 2+ messages in thread
From: ZHANG, Le @ 2011-04-16 20:50 UTC (permalink / raw)
  To: git; +Cc: ZHANG, Le

When not set it defaults to 'verbatim', nothing will be done.
When set, the encoding of the blobs in repository will be converted to it.
The original encoding is get from mail header.

Signed-off-by: ZHANG, Le <r0bertz@gentoo.org>
---
 Documentation/git-mailinfo.txt |    2 +-
 builtin/mailinfo.c             |    6 +++++-
 cache.h                        |    2 ++
 config.c                       |    3 +++
 environment.c                  |    6 ++++++
 5 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/Documentation/git-mailinfo.txt b/Documentation/git-mailinfo.txt
index ed45662..cbdd9bb 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 'i18n.repositoryencoding' for that.
 
 --encoding=<encoding>::
 	Similar to -u.  But when re-coding, the charset specified here is
diff --git a/builtin/mailinfo.c b/builtin/mailinfo.c
index 0f42ff1..51d950b 100644
--- a/builtin/mailinfo.c
+++ b/builtin/mailinfo.c
@@ -12,6 +12,7 @@ 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 *repository_charset;
 static struct strbuf line = STRBUF_INIT;
 static struct strbuf name = STRBUF_INIT;
 static struct strbuf email = STRBUF_INIT;
@@ -824,8 +825,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 (strcasecmp(repository_charset, "verbatim"))
+		convert_to(line, repository_charset, charset.buf);
 	fwrite(line->buf, 1, line->len, patchfile);
 	patch_lines++;
 }
@@ -1030,6 +1033,7 @@ int cmd_mailinfo(int argc, const char **argv, const char *prefix)
 
 	def_charset = get_commit_output_encoding();
 	metainfo_charset = def_charset;
+	repository_charset = get_repository_encoding();
 
 	while (1 < argc && argv[1][0] == '-') {
 		if (!strcmp(argv[1], "-k"))
diff --git a/cache.h b/cache.h
index 2674f4c..ebc3a92 100644
--- a/cache.h
+++ b/cache.h
@@ -1029,6 +1029,7 @@ extern int git_config_system(void);
 extern int config_error_nonbool(const char *);
 extern const char *get_log_output_encoding(void);
 extern const char *get_commit_output_encoding(void);
+extern const char *get_repository_encoding(void);
 
 extern const char *config_exclusive_filename;
 
@@ -1042,6 +1043,7 @@ extern int user_ident_explicitly_given;
 extern int user_ident_sufficiently_given(void);
 
 extern const char *git_commit_encoding;
+extern const char *git_repository_encoding;
 extern const char *git_log_output_encoding;
 extern const char *git_mailmap_file;
 
diff --git a/config.c b/config.c
index 0abcada..35cc09a 100644
--- a/config.c
+++ b/config.c
@@ -691,6 +691,9 @@ static int git_default_i18n_config(const char *var, const char *value)
 	if (!strcmp(var, "i18n.commitencoding"))
 		return git_config_string(&git_commit_encoding, var, value);
 
+	if (!strcmp(var, "i18n.repositoryencoding"))
+		return git_config_string(&git_repository_encoding, var, value);
+
 	if (!strcmp(var, "i18n.logoutputencoding"))
 		return git_config_string(&git_log_output_encoding, var, value);
 
diff --git a/environment.c b/environment.c
index f4549d3..135fdfc 100644
--- a/environment.c
+++ b/environment.c
@@ -24,6 +24,7 @@ int log_all_ref_updates = -1; /* unspecified */
 int warn_ambiguous_refs = 1;
 int repository_format_version;
 const char *git_commit_encoding;
+const char *git_repository_encoding;
 const char *git_log_output_encoding;
 int shared_repository = PERM_UMASK;
 const char *apply_default_whitespace;
@@ -232,3 +233,8 @@ const char *get_commit_output_encoding(void)
 {
 	return git_commit_encoding ? git_commit_encoding : "UTF-8";
 }
+
+const char *get_repository_encoding(void)
+{
+    return git_repository_encoding ? git_repository_encoding : "verbatim";
+}
-- 
1.7.5.rc2.5.gb2ee76.dirty

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH 2/2] i18n.repositoryencoding: a new variable specifying the encoding of blobs in the repository
  2011-04-16 20:50 [PATCH 2/2] i18n.repositoryencoding: a new variable specifying the encoding of blobs in the repository ZHANG, Le
@ 2011-04-19  4:34 ` Junio C Hamano
  0 siblings, 0 replies; 2+ messages in thread
From: Junio C Hamano @ 2011-04-19  4:34 UTC (permalink / raw)
  To: ZHANG, Le; +Cc: git

"ZHANG, Le" <r0bertz@gentoo.org> writes:

> When not set it defaults to 'verbatim', nothing will be done.
> When set, the encoding of the blobs in repository will be converted to it.
> The original encoding is get from mail header.
>
> Signed-off-by: ZHANG, Le <r0bertz@gentoo.org>

As I suspect that you would need to reroll the [PATCH 1/2], my comment on
this patch might become unapplicable, but anyway...

> @@ -824,8 +825,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 (strcasecmp(repository_charset, "verbatim"))
> +		convert_to(line, repository_charset, charset.buf);

I really do not want to see you call this strcasecmp for each and every
line of the input.  The majority of the users (read: the current users who
are fine without using this new feature) do not want to pay the overhead.

How about doing it this way instead:

 - Do not define repository_charset variable in this file; do not define
   get_repository_encoding() function in environment.c; just declare
   "const char *repository_encoding" in cache.h (as "extern const ...")
   and define it in environment.c.

 - git_default_i18n_config() in config.c reads i18n.repositoryencoding
   into "repository_encoding".  This variable is initialized to NULL when
   the program is loaded, and as a special case, when the configuration
   variable is "verbatim", this variable is reset to NULL.  Otherwise it
   will hold a copy of the string given by the configuration file (or -c
   option from the command line).

 - This callsite checks if repository_encoding is non-NULL, and if so
   calls convert_to().

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-04-19  4:34 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-04-16 20:50 [PATCH 2/2] i18n.repositoryencoding: a new variable specifying the encoding of blobs in the repository ZHANG, Le
2011-04-19  4:34 ` Junio C Hamano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).