mirror of
https://github.com/git/git.git
synced 2026-03-14 10:53:25 +01:00
Merge branch 'jc/utf8' into next
* jc/utf8: Teach log family --encoding i18n.logToUTF8: convert commit log message to UTF-8 Move encoding conversion routine out of mailinfo to utf8.c Document git-reset <commit> -- <paths>... Document --numstat in git-apply and git-diff show-branch --reflog: add documentation. add .mailmap for git-shortlog output with the git repository Conflicts: commit.c
This commit is contained in:
61
commit.c
61
commit.c
@@ -2,6 +2,7 @@
|
||||
#include "tag.h"
|
||||
#include "commit.h"
|
||||
#include "pkt-line.h"
|
||||
#include "utf8.h"
|
||||
|
||||
int save_commit_buffer = 1;
|
||||
|
||||
@@ -597,10 +598,53 @@ static int add_merge_info(enum cmit_fmt fmt, char *buf, const struct commit *com
|
||||
return offset;
|
||||
}
|
||||
|
||||
unsigned long pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit,
|
||||
unsigned long len, char *buf, unsigned long space,
|
||||
static char *get_header(const struct commit *commit, const char *key)
|
||||
{
|
||||
int key_len = strlen(key);
|
||||
const char *line = commit->buffer;
|
||||
|
||||
for (;;) {
|
||||
const char *eol = strchr(line, '\n'), *next;
|
||||
|
||||
if (line == eol)
|
||||
return NULL;
|
||||
if (!eol) {
|
||||
eol = line + strlen(line);
|
||||
next = NULL;
|
||||
} else
|
||||
next = eol + 1;
|
||||
if (!strncmp(line, key, key_len) && line[key_len] == ' ') {
|
||||
int len = eol - line - key_len;
|
||||
char *ret = xmalloc(len);
|
||||
memcpy(ret, line + key_len + 1, len - 1);
|
||||
ret[len - 1] = '\0';
|
||||
return ret;
|
||||
}
|
||||
line = next;
|
||||
}
|
||||
}
|
||||
|
||||
static char *logmsg_reencode(const struct commit *commit)
|
||||
{
|
||||
char *encoding = get_header(commit, "encoding");
|
||||
char *out;
|
||||
|
||||
if (!encoding || !strcmp(encoding, git_commit_encoding))
|
||||
return NULL;
|
||||
out = reencode_string(commit->buffer, git_commit_encoding, encoding);
|
||||
free(encoding);
|
||||
if (!out)
|
||||
return NULL;
|
||||
return out;
|
||||
}
|
||||
|
||||
unsigned long pretty_print_commit(enum cmit_fmt fmt,
|
||||
const struct commit *commit,
|
||||
unsigned long len,
|
||||
char *buf, unsigned long space,
|
||||
int abbrev, const char *subject,
|
||||
const char *after_subject, int relative_date)
|
||||
const char *after_subject,
|
||||
int relative_date)
|
||||
{
|
||||
int hdr = 1, body = 0;
|
||||
unsigned long offset = 0;
|
||||
@@ -608,6 +652,15 @@ unsigned long pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit
|
||||
int parents_shown = 0;
|
||||
const char *msg = commit->buffer;
|
||||
int plain_non_ascii = 0;
|
||||
char *reencoded = NULL;
|
||||
|
||||
if (*git_commit_encoding) {
|
||||
reencoded = logmsg_reencode(commit);
|
||||
if (reencoded) {
|
||||
msg = reencoded;
|
||||
len = strlen(msg);
|
||||
}
|
||||
}
|
||||
|
||||
if (fmt == CMIT_FMT_ONELINE || fmt == CMIT_FMT_EMAIL)
|
||||
indent = 0;
|
||||
@@ -755,6 +808,8 @@ unsigned long pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit
|
||||
if (fmt == CMIT_FMT_EMAIL && !body)
|
||||
buf[offset++] = '\n';
|
||||
buf[offset] = '\0';
|
||||
|
||||
free(reencoded);
|
||||
return offset;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user