builtin-blame: Reencode commit messages according to git-log rules.
Currently git-blame outputs text from the commit messages (e.g. the author name and the summary string) as-is, without even providing any information about the encoding used for the data. It makes interpreting the data in multilingual environment very difficult. This commit changes the blame implementation to recode the messages using the rules used by other commands like git-log. Namely, the target encoding can be specified through the i18n.commitEncoding or i18n.logOutputEncoding options, or directly on the command line using the --encoding parameter. Converting the encoding before output seems to be more friendly to the porcelain tools than simply providing the value of the encoding header, and does not require changing the output format. If anybody needs the old behavior, it is possible to achieve it by specifying --encoding=none. Signed-off-by: Alexander Gavrilov <angavrilov@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
committed by
Junio C Hamano
parent
208f689610
commit
69cd8f6342
@ -1431,7 +1431,7 @@ static void get_commit_info(struct commit *commit,
|
||||
int detailed)
|
||||
{
|
||||
int len;
|
||||
char *tmp, *endp;
|
||||
char *tmp, *endp, *reencoded, *message;
|
||||
static char author_buf[1024];
|
||||
static char committer_buf[1024];
|
||||
static char summary_buf[1024];
|
||||
@ -1449,24 +1449,29 @@ static void get_commit_info(struct commit *commit,
|
||||
die("Cannot read commit %s",
|
||||
sha1_to_hex(commit->object.sha1));
|
||||
}
|
||||
reencoded = reencode_commit_message(commit, NULL);
|
||||
message = reencoded ? reencoded : commit->buffer;
|
||||
ret->author = author_buf;
|
||||
get_ac_line(commit->buffer, "\nauthor ",
|
||||
get_ac_line(message, "\nauthor ",
|
||||
sizeof(author_buf), author_buf, &ret->author_mail,
|
||||
&ret->author_time, &ret->author_tz);
|
||||
|
||||
if (!detailed)
|
||||
if (!detailed) {
|
||||
free(reencoded);
|
||||
return;
|
||||
}
|
||||
|
||||
ret->committer = committer_buf;
|
||||
get_ac_line(commit->buffer, "\ncommitter ",
|
||||
get_ac_line(message, "\ncommitter ",
|
||||
sizeof(committer_buf), committer_buf, &ret->committer_mail,
|
||||
&ret->committer_time, &ret->committer_tz);
|
||||
|
||||
ret->summary = summary_buf;
|
||||
tmp = strstr(commit->buffer, "\n\n");
|
||||
tmp = strstr(message, "\n\n");
|
||||
if (!tmp) {
|
||||
error_out:
|
||||
sprintf(summary_buf, "(%s)", sha1_to_hex(commit->object.sha1));
|
||||
free(reencoded);
|
||||
return;
|
||||
}
|
||||
tmp += 2;
|
||||
@ -1478,6 +1483,7 @@ static void get_commit_info(struct commit *commit,
|
||||
goto error_out;
|
||||
memcpy(summary_buf, tmp, len);
|
||||
summary_buf[len] = 0;
|
||||
free(reencoded);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user