{"thread":{"id":"15987","subject":"[RFC PATCH] builtin-blame: Reencode commit messages according to git-log rules.","startedAt":"2008-10-20T21:24:39Z","lastAt":"2008-10-21T07:34:05Z","messageCount":2,"participants":["Alexander Gavrilov","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"93557","messageId":"1224537879-13000-1-git-send-email-angavrilov@gmail.com","threadId":"15987","inReplyTo":null,"subject":"[RFC PATCH] builtin-blame: Reencode commit messages according to git-log rules.","fromName":"Alexander Gavrilov","fromEmail":"angavrilov@gmail.com","sentAt":"2008-10-20T21:24:39Z","receivedAt":"2008-10-20T21:24:39Z","isPatch":true,"sender":{"key":"angavrilov@gmail.com","avatar":"https://avatars.githubusercontent.com/u/42666?v=4"},"body":"Currently git-blame outputs text from the commit messages\n(e.g. the author name and the summary string) as-is, without\neven providing any information about the encoding used for\nthe data. It makes interpreting the data in multilingual\nenvironment very difficult.\n\nThis commit changes the blame implementation to recode the\nmessages using the rules used by other commands like git-log.\nNamely, the target encoding can be specified through the\ni18n.commitEncoding or i18n.logOutputEncoding options, or\ndirectly on the command line using the --encoding parameter.\n\nConverting the encoding before output seems to be more\nfriendly to the porcelain tools than simply providing the\nvalue of the encoding header, and does not require changing\nthe output format.\n\nIf anybody needs the old behavior, it is possible to\nachieve it by specifying --encoding=none.\n\nSigned-off-by: Alexander Gavrilov <angavrilov@gmail.com>\n---\n Documentation/blame-options.txt |    7 +++++++\n Documentation/i18n.txt          |    6 +++---\n builtin-blame.c                 |   16 +++++++++++-----\n commit.h                        |    2 ++\n pretty.c                        |   21 +++++++++++++++------\n 5 files changed, 38 insertions(+), 14 deletions(-)\n\ndiff --git a/Documentation/blame-options.txt b/Documentation/blame-options.txt\nindex 5428111..51e7f9f 100644\n--- a/Documentation/blame-options.txt\n+++ b/Documentation/blame-options.txt\n@@ -49,6 +49,13 @@ of lines before or after the line given by <start>.\n \tShow the result incrementally in a format designed for\n \tmachine consumption.\n \n+--encoding=<encoding>::\n+\tSpecifies the encoding used to output author names\n+\tand commit summaries. Setting it to `none` makes blame\n+\toutput unconverted data. For more information see the\n+\tdiscussion about encoding in the linkgit:git-log[1]\n+\tmanual page.\n+\n --contents <file>::\n \tWhen <rev> is not specified, the command annotates the\n \tchanges starting backwards from the working tree copy.\ndiff --git a/Documentation/i18n.txt b/Documentation/i18n.txt\nindex d2970f8..2cdacd9 100644\n--- a/Documentation/i18n.txt\n+++ b/Documentation/i18n.txt\n@@ -37,9 +37,9 @@ of `i18n.commitencoding` in its `encoding` header.  This is to\n help other people who look at them later.  Lack of this header\n implies that the commit log message is encoded in UTF-8.\n \n-. 'git-log', 'git-show' and friends looks at the `encoding`\n-  header of a commit object, and tries to re-code the log\n-  message into UTF-8 unless otherwise specified.  You can\n+. 'git-log', 'git-show', 'git-blame' and friends look at the\n+  `encoding` header of a commit object, and try to re-code the\n+  log message into UTF-8 unless otherwise specified.  You can\n   specify the desired output encoding with\n   `i18n.logoutputencoding` in `.git/config` file, like this:\n +\ndiff --git a/builtin-blame.c b/builtin-blame.c\nindex 48cc0c1..a806036 100644\n--- a/builtin-blame.c\n+++ b/builtin-blame.c\n@@ -1431,7 +1431,7 @@ static void get_commit_info(struct commit *commit,\n \t\t\t    int detailed)\n {\n \tint len;\n-\tchar *tmp, *endp;\n+\tchar *tmp, *endp, *reencoded, *message;\n \tstatic char author_buf[1024];\n \tstatic char committer_buf[1024];\n \tstatic char summary_buf[1024];\n@@ -1449,24 +1449,29 @@ static void get_commit_info(struct commit *commit,\n \t\t\tdie(\"Cannot read commit %s\",\n \t\t\t    sha1_to_hex(commit->object.sha1));\n \t}\n+\treencoded = reencode_commit_message(commit, NULL);\n+\tmessage   = reencoded ? reencoded : commit->buffer;\n \tret->author = author_buf;\n-\tget_ac_line(commit->buffer, \"\\nauthor \",\n+\tget_ac_line(message, \"\\nauthor \",\n \t\t    sizeof(author_buf), author_buf, &ret->author_mail,\n \t\t    &ret->author_time, &ret->author_tz);\n \n-\tif (!detailed)\n+\tif (!detailed) {\n+\t\tfree(reencoded);\n \t\treturn;\n+\t}\n \n \tret->committer = committer_buf;\n-\tget_ac_line(commit->buffer, \"\\ncommitter \",\n+\tget_ac_line(message, \"\\ncommitter \",\n \t\t    sizeof(committer_buf), committer_buf, &ret->committer_mail,\n \t\t    &ret->committer_time, &ret->committer_tz);\n \n \tret->summary = summary_buf;\n-\ttmp = strstr(commit->buffer, \"\\n\\n\");\n+\ttmp = strstr(message, \"\\n\\n\");\n \tif (!tmp) {\n \terror_out:\n \t\tsprintf(summary_buf, \"(%s)\", sha1_to_hex(commit->object.sha1));\n+\t\tfree(reencoded);\n \t\treturn;\n \t}\n \ttmp += 2;\n@@ -1478,6 +1483,7 @@ static void get_commit_info(struct commit *commit,\n \t\tgoto error_out;\n \tmemcpy(summary_buf, tmp, len);\n \tsummary_buf[len] = 0;\n+\tfree(reencoded);\n }\n \n /*\ndiff --git a/commit.h b/commit.h\nindex 4c05864..c73fb2d 100644\n--- a/commit.h\n+++ b/commit.h\n@@ -65,6 +65,8 @@ enum cmit_fmt {\n \n extern int non_ascii(int);\n struct rev_info; /* in revision.h, it circularly uses enum cmit_fmt */\n+extern char *reencode_commit_message(const struct commit *commit,\n+\t\t\t\t     const char **encoding_p);\n extern void get_commit_format(const char *arg, struct rev_info *);\n extern void format_commit_message(const struct commit *commit,\n \t\t\t\t  const void *format, struct strbuf *sb,\ndiff --git a/pretty.c b/pretty.c\nindex 1e79943..58c8c11 100644\n--- a/pretty.c\n+++ b/pretty.c\n@@ -783,6 +783,20 @@ void pp_remainder(enum cmit_fmt fmt,\n \t}\n }\n \n+char *reencode_commit_message(const struct commit *commit, const char **encoding_p)\n+{\n+\tconst char *encoding;\n+\n+\tencoding = (git_log_output_encoding\n+\t\t    ? git_log_output_encoding\n+\t\t    : git_commit_encoding);\n+\tif (!encoding)\n+\t\tencoding = \"utf-8\";\n+\tif (encoding_p)\n+\t\t*encoding_p = encoding;\n+\treturn logmsg_reencode(commit, encoding);\n+}\n+\n void pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit,\n \t\t\t struct strbuf *sb, int abbrev,\n \t\t\t const char *subject, const char *after_subject,\n@@ -799,12 +813,7 @@ void pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit,\n \t\treturn;\n \t}\n \n-\tencoding = (git_log_output_encoding\n-\t\t    ? git_log_output_encoding\n-\t\t    : git_commit_encoding);\n-\tif (!encoding)\n-\t\tencoding = \"utf-8\";\n-\treencoded = logmsg_reencode(commit, encoding);\n+\treencoded = reencode_commit_message(commit, &encoding);\n \tif (reencoded) {\n \t\tmsg = reencoded;\n \t}\n-- \n1.6.0.20.g6148bc\n"},{"id":"93582","messageId":"7viqrmz9jm.fsf@gitster.siamese.dyndns.org","threadId":"15987","inReplyTo":"1224537879-13000-1-git-send-email-angavrilov@gmail.com","subject":"Re: [RFC PATCH] builtin-blame: Reencode commit messages according to git-log rules.","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-10-21T07:34:05Z","receivedAt":"2008-10-21T07:34:05Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"I think this makes sense.  We'd want a testcase for the new feature before\napplying the patch, though.\n"}]}