i18n.logToUTF8: convert commit log message to UTF-8
When i18n.commitencoding is set to a non UTF-8 encoding, commit-tree records the encoding in an extra header after author/committer headers in the commit object. An earlier version used trailer but Johannes points out that there is little risk breaking existing Porcelains with a new header. Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Dec 23, 2006 at 23:53 UTC
4b2bced55948422198dad92dcbf4b5b98913f1e7
1 file changed
+9
-2
builtin-commit-tree.c
+9
-2
@@ -92,6 +92,7 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix)
92
char comment[1000];
93
char *buffer;
94
unsigned int size;
95
+ int encoding_is_utf8;
96
97
setup_ident();
98
git_config(git_default_config);
@@ -117,6 +118,8 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix)
118
parents++;
119
}
120
121
+ encoding_is_utf8 = !strcmp(git_commit_encoding, "utf-8");
122
+
123
init_buffer(&buffer, &size);
124
add_buffer(&buffer, &size, "tree %s\n", sha1_to_hex(tree_sha1));
125
@@ -130,7 +133,11 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix)
133
134
/* Person/date information */
135
add_buffer(&buffer, &size, "author %s\n", git_author_info(1));
133
- add_buffer(&buffer, &size, "committer %s\n\n", git_committer_info(1));
136
+ add_buffer(&buffer, &size, "committer %s\n", git_committer_info(1));
137
+ if (!encoding_is_utf8)
138
+ add_buffer(&buffer, &size,
139
+ "encoding %s\n", git_commit_encoding);
140
+ add_buffer(&buffer, &size, "\n");
141
142
/* And add the comment */
143
while (fgets(comment, sizeof(comment), stdin) != NULL)
@@ -138,7 +145,7 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix)
145
146
/* And check the encoding */
147
buffer[size] = '\0';
141
- if (!strcmp(git_commit_encoding, "utf-8") && !is_utf8(buffer))
148
+ if (encoding_is_utf8 && !is_utf8(buffer))
149
fprintf(stderr, commit_utf8_warn);
150
151
if (!write_sha1_file(buffer, size, commit_type, commit_sha1)) {