git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Johannes Schindelin <Johannes.Schindelin@gmx.de>
To: Junio C Hamano <junkio@cox.net>
Cc: "Nicolas Pitre" <nico@cam.org>,
	"Uwe Kleine-König" <zeisberg@informatik.uni-freiburg.de>,
	git@vger.kernel.org
Subject: [PATCH 2/2] git-commit-tree: if i18n.commitencoding is utf-8 (default), check it
Date: Fri, 22 Dec 2006 22:06:08 +0100 (CET)	[thread overview]
Message-ID: <Pine.LNX.4.63.0612222204010.19693@wbgn013.biozentrum.uni-wuerzburg.de> (raw)
In-Reply-To: <7vslf7zrdp.fsf@assigned-by-dhcp.cox.net>


Now, git-commit-tree refuses to commit when i18n.commitencoding is
either unset, or set to "utf-8", and the commit message does not
minimally conform to the UTF-8 encoding.

Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
---

	Unfortunately, I could not think of a shorter oneline description. 
	But my next patch fixes at least the output in shortlog.

 builtin-commit-tree.c |   14 ++++++++++++--
 1 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/builtin-commit-tree.c b/builtin-commit-tree.c
index 856f3cd..810b440 100644
--- a/builtin-commit-tree.c
+++ b/builtin-commit-tree.c
@@ -7,6 +7,7 @@
 #include "commit.h"
 #include "tree.h"
 #include "builtin.h"
+#include "utf8.h"
 
 #define BLOCKING (1ul << 14)
 
@@ -32,7 +33,7 @@ static void add_buffer(char **bufp, unsigned int *sizep, const char *fmt, ...)
 	len = vsnprintf(one_line, sizeof(one_line), fmt, args);
 	va_end(args);
 	size = *sizep;
-	newsize = size + len;
+	newsize = size + len + 1;
 	alloc = (size + 32767) & ~32767;
 	buf = *bufp;
 	if (newsize > alloc) {
@@ -40,7 +41,7 @@ static void add_buffer(char **bufp, unsigned int *sizep, const char *fmt, ...)
 		buf = xrealloc(buf, alloc);
 		*bufp = buf;
 	}
-	*sizep = newsize;
+	*sizep = newsize - 1;
 	memcpy(buf + size, one_line, len);
 }
 
@@ -127,6 +128,15 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix)
 	while (fgets(comment, sizeof(comment), stdin) != NULL)
 		add_buffer(&buffer, &size, "%s", comment);
 
+	/* And check the encoding */
+	buffer[size] = '\0';
+	if (!strcmp(git_commit_encoding, "utf-8") && utf8_strlen(buffer) < 0) {
+		fprintf(stderr, "Commit message does not conform to UTF-8.\n"
+			"Please fix the message,"
+			" or set the config variable i18n.commitencoding.\n");
+		return 1;
+	}
+
 	if (!write_sha1_file(buffer, size, commit_type, commit_sha1)) {
 		printf("%s\n", sha1_to_hex(commit_sha1));
 		return 0;
-- 
1.4.4.3.ge5f98-dirty

  parent reply	other threads:[~2006-12-22 21:06 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-12-08 11:44 [PATCH] Fix documentation copy&paste typo Uwe Kleine-Koenig
2006-12-19 14:16 ` Uwe Kleine-König
2006-12-19 17:27   ` Junio C Hamano
2006-12-21  8:59     ` specify charset for commits (Was: [PATCH] Fix documentation copy&paste typo) Uwe Kleine-König
2006-12-21  9:51       ` Johannes Schindelin
2006-12-21 10:11         ` Santi Béjar
2006-12-21 10:23         ` Alexander Litvinov
2006-12-21 10:52           ` Jakub Narebski
2006-12-21 13:05             ` Alexander Litvinov
2006-12-21 13:14               ` Jakub Narebski
2006-12-21 13:43             ` Uwe Kleine-König
2006-12-21 18:19           ` specify charset for commits Junio C Hamano
2006-12-21 18:48             ` Nicolas Pitre
2006-12-21 19:11             ` Uwe Kleine-König
2006-12-21 19:36             ` Alexander Litvinov
2006-12-22 12:07             ` Johannes Schindelin
2006-12-22 15:09               ` Uwe Kleine-König
2006-12-22 22:02                 ` Uwe Kleine-König
2006-12-22 15:31               ` Nicolas Pitre
2006-12-22 19:01                 ` Junio C Hamano
2006-12-22 21:03                   ` [PATCH 1/2] libgit.a: add some UTF-8 handling functions Johannes Schindelin
2006-12-22 21:27                     ` Junio C Hamano
2006-12-22 21:36                       ` Johannes Schindelin
2006-12-22 21:58                         ` Junio C Hamano
2006-12-22 22:20                           ` Johannes Schindelin
2006-12-22 22:33                             ` Junio C Hamano
2006-12-25  4:03                             ` Alexander Litvinov
2006-12-22 22:14                         ` Uwe Kleine-König
2006-12-22 22:19                     ` Uwe Kleine-König
2006-12-22 22:34                       ` Johannes Schindelin
2006-12-22 23:50                         ` Johannes Schindelin
2006-12-23  8:52                           ` Uwe Kleine-König
2006-12-23 14:12                             ` Johannes Schindelin
2006-12-23 19:53                           ` warn non utf-8 commit log messages Junio C Hamano
2006-12-23 23:46                             ` Johannes Schindelin
2006-12-22 21:06                   ` Johannes Schindelin [this message]
2006-12-22 21:50                     ` [PATCH 2/2] git-commit-tree: if i18n.commitencoding is utf-8 (default), check it Junio C Hamano
2006-12-22 22:21                       ` Johannes Schindelin
2006-12-22 21:15                   ` [RFC/PATCH 3/2] Wrap lines in shortlog Johannes Schindelin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.LNX.4.63.0612222204010.19693@wbgn013.biozentrum.uni-wuerzburg.de \
    --to=johannes.schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=junkio@cox.net \
    --cc=nico@cam.org \
    --cc=zeisberg@informatik.uni-freiburg.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).