{"thread":{"id":"27119","subject":"[PATCH 2/2] i18n.repositoryencoding: a new variable specifying the encoding of blobs in the repository","startedAt":"2011-04-16T20:50:04Z","lastAt":"2011-04-19T04:34:13Z","messageCount":2,"participants":["ZHANG, Le","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"165984","messageId":"1302987004-28134-1-git-send-email-r0bertz@gentoo.org","threadId":"27119","inReplyTo":null,"subject":"[PATCH 2/2] i18n.repositoryencoding: a new variable specifying the encoding of blobs in the repository","fromName":"ZHANG, Le","fromEmail":"r0bertz@gentoo.org","sentAt":"2011-04-16T20:50:04Z","receivedAt":"2011-04-16T20:50:04Z","isPatch":true,"sender":{"key":"r0bertz@gentoo.org","avatar":"https://avatars.githubusercontent.com/u/29025?v=4"},"body":"When not set it defaults to 'verbatim', nothing will be done.\nWhen set, the encoding of the blobs in repository will be converted to it.\nThe original encoding is get from mail header.\n\nSigned-off-by: ZHANG, Le <r0bertz@gentoo.org>\n---\n Documentation/git-mailinfo.txt |    2 +-\n builtin/mailinfo.c             |    6 +++++-\n cache.h                        |    2 ++\n config.c                       |    3 +++\n environment.c                  |    6 ++++++\n 5 files changed, 17 insertions(+), 2 deletions(-)\n\ndiff --git a/Documentation/git-mailinfo.txt b/Documentation/git-mailinfo.txt\nindex ed45662..cbdd9bb 100644\n--- a/Documentation/git-mailinfo.txt\n+++ b/Documentation/git-mailinfo.txt\n@@ -45,7 +45,7 @@ OPTIONS\n \tthem.  This used to be optional but now it is the default.\n +\n Note that the patch is always used as-is without charset\n-conversion, even with this flag.\n+conversion, even with this flag; use 'i18n.repositoryencoding' for that.\n \n --encoding=<encoding>::\n \tSimilar to -u.  But when re-coding, the charset specified here is\ndiff --git a/builtin/mailinfo.c b/builtin/mailinfo.c\nindex 0f42ff1..51d950b 100644\n--- a/builtin/mailinfo.c\n+++ b/builtin/mailinfo.c\n@@ -12,6 +12,7 @@ static FILE *cmitmsg, *patchfile, *fin, *fout;\n static int keep_subject;\n static int keep_non_patch_brackets_in_subject;\n static const char *metainfo_charset;\n+static const char *repository_charset;\n static struct strbuf line = STRBUF_INIT;\n static struct strbuf name = STRBUF_INIT;\n static struct strbuf email = STRBUF_INIT;\n@@ -824,8 +825,10 @@ static int handle_commit_msg(struct strbuf *line)\n \treturn 0;\n }\n \n-static void handle_patch(const struct strbuf *line)\n+static void handle_patch(struct strbuf *line)\n {\n+\tif (strcasecmp(repository_charset, \"verbatim\"))\n+\t\tconvert_to(line, repository_charset, charset.buf);\n \tfwrite(line->buf, 1, line->len, patchfile);\n \tpatch_lines++;\n }\n@@ -1030,6 +1033,7 @@ int cmd_mailinfo(int argc, const char **argv, const char *prefix)\n \n \tdef_charset = get_commit_output_encoding();\n \tmetainfo_charset = def_charset;\n+\trepository_charset = get_repository_encoding();\n \n \twhile (1 < argc && argv[1][0] == '-') {\n \t\tif (!strcmp(argv[1], \"-k\"))\ndiff --git a/cache.h b/cache.h\nindex 2674f4c..ebc3a92 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1029,6 +1029,7 @@ extern int git_config_system(void);\n extern int config_error_nonbool(const char *);\n extern const char *get_log_output_encoding(void);\n extern const char *get_commit_output_encoding(void);\n+extern const char *get_repository_encoding(void);\n \n extern const char *config_exclusive_filename;\n \n@@ -1042,6 +1043,7 @@ extern int user_ident_explicitly_given;\n extern int user_ident_sufficiently_given(void);\n \n extern const char *git_commit_encoding;\n+extern const char *git_repository_encoding;\n extern const char *git_log_output_encoding;\n extern const char *git_mailmap_file;\n \ndiff --git a/config.c b/config.c\nindex 0abcada..35cc09a 100644\n--- a/config.c\n+++ b/config.c\n@@ -691,6 +691,9 @@ static int git_default_i18n_config(const char *var, const char *value)\n \tif (!strcmp(var, \"i18n.commitencoding\"))\n \t\treturn git_config_string(&git_commit_encoding, var, value);\n \n+\tif (!strcmp(var, \"i18n.repositoryencoding\"))\n+\t\treturn git_config_string(&git_repository_encoding, var, value);\n+\n \tif (!strcmp(var, \"i18n.logoutputencoding\"))\n \t\treturn git_config_string(&git_log_output_encoding, var, value);\n \ndiff --git a/environment.c b/environment.c\nindex f4549d3..135fdfc 100644\n--- a/environment.c\n+++ b/environment.c\n@@ -24,6 +24,7 @@ int log_all_ref_updates = -1; /* unspecified */\n int warn_ambiguous_refs = 1;\n int repository_format_version;\n const char *git_commit_encoding;\n+const char *git_repository_encoding;\n const char *git_log_output_encoding;\n int shared_repository = PERM_UMASK;\n const char *apply_default_whitespace;\n@@ -232,3 +233,8 @@ const char *get_commit_output_encoding(void)\n {\n \treturn git_commit_encoding ? git_commit_encoding : \"UTF-8\";\n }\n+\n+const char *get_repository_encoding(void)\n+{\n+    return git_repository_encoding ? git_repository_encoding : \"verbatim\";\n+}\n-- \n1.7.5.rc2.5.gb2ee76.dirty\n"},{"id":"166060","messageId":"7vy6366ere.fsf@alter.siamese.dyndns.org","threadId":"27119","inReplyTo":"1302987004-28134-1-git-send-email-r0bertz@gentoo.org","subject":"Re: [PATCH 2/2] i18n.repositoryencoding: a new variable specifying the encoding of blobs in the repository","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2011-04-19T04:34:13Z","receivedAt":"2011-04-19T04:34:13Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"ZHANG, Le\" <r0bertz@gentoo.org> writes:\n\n> When not set it defaults to 'verbatim', nothing will be done.\n> When set, the encoding of the blobs in repository will be converted to it.\n> The original encoding is get from mail header.\n>\n> Signed-off-by: ZHANG, Le <r0bertz@gentoo.org>\n\nAs I suspect that you would need to reroll the [PATCH 1/2], my comment on\nthis patch might become unapplicable, but anyway...\n\n> @@ -824,8 +825,10 @@ static int handle_commit_msg(struct strbuf *line)\n>  \treturn 0;\n>  }\n>  \n> -static void handle_patch(const struct strbuf *line)\n> +static void handle_patch(struct strbuf *line)\n>  {\n> +\tif (strcasecmp(repository_charset, \"verbatim\"))\n> +\t\tconvert_to(line, repository_charset, charset.buf);\n\nI really do not want to see you call this strcasecmp for each and every\nline of the input.  The majority of the users (read: the current users who\nare fine without using this new feature) do not want to pay the overhead.\n\nHow about doing it this way instead:\n\n - Do not define repository_charset variable in this file; do not define\n   get_repository_encoding() function in environment.c; just declare\n   \"const char *repository_encoding\" in cache.h (as \"extern const ...\")\n   and define it in environment.c.\n\n - git_default_i18n_config() in config.c reads i18n.repositoryencoding\n   into \"repository_encoding\".  This variable is initialized to NULL when\n   the program is loaded, and as a special case, when the configuration\n   variable is \"verbatim\", this variable is reset to NULL.  Otherwise it\n   will hold a copy of the string given by the configuration file (or -c\n   option from the command line).\n\n - This callsite checks if repository_encoding is non-NULL, and if so\n   calls convert_to().\n"}]}