summaryrefslogtreecommitdiff
path: root/commit.c
diff options
context:
space:
mode:
authorJunio C Hamano <junkio@cox.net>2006-12-30 22:42:43 -0800
committerJunio C Hamano <junkio@cox.net>2006-12-30 22:42:43 -0800
commit76d4e079adba461c127641a1104772a62e38cd81 (patch)
tree7a8e335ed577aff47b5a80d8de5a6d7904813c02 /commit.c
parent2c039da804ee0542ff41d2f22a444d04a2d37856 (diff)
parenta862f97e98decc317437fa3b04081f68fb4ffbf3 (diff)
downloadgit-76d4e079adba461c127641a1104772a62e38cd81.tar.gz
Merge branch 'master' into sp/mmap
* master: Documentation/config.txt (and repo-config manpage): mark-up fix. Teach Git how to parse standard power of 2 suffixes. Use /dev/null for update hook stdin. Redirect update hook stdout to stderr. Remove unnecessary argc parameter from run_command_v. Automatically detect a bare git repository. Replace "GIT_DIR" with GIT_DIR_ENVIRONMENT. Use PATH_MAX constant for --bare. Force core.filemode to false on Cygwin. Fix formatting for urls section of fetch, pull, and push manpages Fix yet another subtle xdl_merge() bug i18n: drop "encoding" header in the output after re-coding. commit-tree: cope with different ways "utf-8" can be spelled. Move commit reencoding parameter parsing to revision.c Documentation: minor rewording for git-log and git-show pages. Documentation: i18n commit log message notes. t3900: test log --encoding=none commit re-encoding: fix confusion between no and default conversion.
Diffstat (limited to 'commit.c')
-rw-r--r--commit.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/commit.c b/commit.c
index eb06afbbe0..afdf27eece 100644
--- a/commit.c
+++ b/commit.c
@@ -624,6 +624,48 @@ static char *get_header(const struct commit *commit, const char *key)
}
}
+static char *replace_encoding_header(char *buf, char *encoding)
+{
+ char *encoding_header = strstr(buf, "\nencoding ");
+ char *end_of_encoding_header;
+ int encoding_header_pos;
+ int encoding_header_len;
+ int new_len;
+ int need_len;
+ int buflen = strlen(buf) + 1;
+
+ if (!encoding_header)
+ return buf; /* should not happen but be defensive */
+ encoding_header++;
+ end_of_encoding_header = strchr(encoding_header, '\n');
+ if (!end_of_encoding_header)
+ return buf; /* should not happen but be defensive */
+ end_of_encoding_header++;
+
+ encoding_header_len = end_of_encoding_header - encoding_header;
+ encoding_header_pos = encoding_header - buf;
+
+ if (is_encoding_utf8(encoding)) {
+ /* we have re-coded to UTF-8; drop the header */
+ memmove(encoding_header, end_of_encoding_header,
+ buflen - (encoding_header_pos + encoding_header_len));
+ return buf;
+ }
+ new_len = strlen(encoding);
+ need_len = new_len + strlen("encoding \n");
+ if (encoding_header_len < need_len) {
+ buf = xrealloc(buf, buflen + (need_len - encoding_header_len));
+ encoding_header = buf + encoding_header_pos;
+ end_of_encoding_header = encoding_header + encoding_header_len;
+ }
+ memmove(end_of_encoding_header + (need_len - encoding_header_len),
+ end_of_encoding_header,
+ buflen - (encoding_header_pos + encoding_header_len));
+ memcpy(encoding_header + 9, encoding, strlen(encoding));
+ encoding_header[9 + new_len] = '\n';
+ return buf;
+}
+
static char *logmsg_reencode(const struct commit *commit)
{
char *encoding;
@@ -633,6 +675,8 @@ static char *logmsg_reencode(const struct commit *commit)
: git_commit_encoding);
if (!output_encoding)
+ output_encoding = "utf-8";
+ else if (!*output_encoding)
return NULL;
encoding = get_header(commit, "encoding");
if (!encoding || !strcmp(encoding, output_encoding)) {
@@ -640,6 +684,9 @@ static char *logmsg_reencode(const struct commit *commit)
return NULL;
}
out = reencode_string(commit->buffer, output_encoding, encoding);
+ if (out)
+ out = replace_encoding_header(out, output_encoding);
+
free(encoding);
if (!out)
return NULL;