git-svn: don't write to the config file from --follow-parent
[gitweb.git] / builtin-commit-tree.c
index f641787988e197209f097cbc9d1b260a2cb6d9d8..2a818a0a2c218b5b98d82ab0d8be0c65c1edf9c0 100644 (file)
@@ -92,8 +92,8 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix)
        char comment[1000];
        char *buffer;
        unsigned int size;
+       int encoding_is_utf8;
 
-       setup_ident();
        git_config(git_default_config);
 
        if (argc < 2)
@@ -117,6 +117,9 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix)
                        parents++;
        }
 
+       /* Not having i18n.commitencoding is the same as having utf-8 */
+       encoding_is_utf8 = is_encoding_utf8(git_commit_encoding);
+
        init_buffer(&buffer, &size);
        add_buffer(&buffer, &size, "tree %s\n", sha1_to_hex(tree_sha1));
 
@@ -130,7 +133,11 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix)
 
        /* Person/date information */
        add_buffer(&buffer, &size, "author %s\n", git_author_info(1));
-       add_buffer(&buffer, &size, "committer %s\n\n", git_committer_info(1));
+       add_buffer(&buffer, &size, "committer %s\n", git_committer_info(1));
+       if (!encoding_is_utf8)
+               add_buffer(&buffer, &size,
+                               "encoding %s\n", git_commit_encoding);
+       add_buffer(&buffer, &size, "\n");
 
        /* And add the comment */
        while (fgets(comment, sizeof(comment), stdin) != NULL)
@@ -138,7 +145,7 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix)
 
        /* And check the encoding */
        buffer[size] = '\0';
-       if (!strcmp(git_commit_encoding, "utf-8") && !is_utf8(buffer))
+       if (encoding_is_utf8 && !is_utf8(buffer))
                fprintf(stderr, commit_utf8_warn);
 
        if (!write_sha1_file(buffer, size, commit_type, commit_sha1)) {