git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Torsten Bögershausen" <tboegi@web.de>
To: Junio C Hamano <gitster@pobox.com>
Cc: "Torsten Bögershausen" <tboegi@web.de>,
	"Robin Rosenberg" <robin.rosenberg@dewire.com>,
	git@vger.kernel.org
Subject: Re: [PATCH] precompose-utf8: do not call checks for non-ascii "utf8"
Date: Mon, 20 Aug 2012 21:46:18 +0200	[thread overview]
Message-ID: <5032940A.4040005@web.de> (raw)
In-Reply-To: <7vobm5jusz.fsf_-_@alter.siamese.dyndns.org>

On 08/20/2012 08:13 PM, Junio C Hamano wrote:
> As suggested by Linus, this function is not checking UTF-8-ness of the
> string; it only is seeing if it is pure US-ASCII.
>
> Signed-off-by: Junio C Hamano <gitster@pobox.com>
> ---
>
>   * Just for completeness, this on top.
>
>   compat/precompose_utf8.c | 16 ++++++++--------
>   1 file changed, 8 insertions(+), 8 deletions(-)
>
> diff --git a/compat/precompose_utf8.c b/compat/precompose_utf8.c
> index 3190d50..8cf5955 100644
> --- a/compat/precompose_utf8.c
> +++ b/compat/precompose_utf8.c
> @@ -13,20 +13,20 @@ typedef char *iconv_ibp;
>   static const char *repo_encoding = "UTF-8";
>   static const char *path_encoding = "UTF-8-MAC";
>
> -static size_t has_utf8(const char *s, size_t maxlen, size_t *strlen_c)
> +static size_t has_non_ascii(const char *s, size_t maxlen, size_t *strlen_c)
>   {
> -	const uint8_t *utf8p = (const uint8_t *)s;
> +	const uint8_t *ptr = (const uint8_t *)s;
>   	size_t strlen_chars = 0;
>   	size_t ret = 0;
>
> -	if (!utf8p || !*utf8p)
> +	if (!ptr || !*ptr)
>   		return 0;
>
> -	while (*utf8p && maxlen) {
> -		if (*utf8p & 0x80)
> +	while (*ptr && maxlen) {
> +		if (*ptr & 0x80)
>   			ret++;
>   		strlen_chars++;
> -		utf8p++;
> +		ptr++;
>   		maxlen--;
>   	}
>   	if (strlen_c)
> @@ -77,7 +77,7 @@ void precompose_argv(int argc, const char **argv)
>   	while (i < argc) {
>   		size_t namelen;
>   		oldarg = argv[i];
> -		if (has_utf8(oldarg, (size_t)-1, &namelen)) {
> +		if (has_non_ascii(oldarg, (size_t)-1, &namelen)) {
>   			newarg = reencode_string_iconv(oldarg, namelen, ic_precompose);
>   			if (newarg)
>   				argv[i] = newarg;
> @@ -130,7 +130,7 @@ struct dirent_prec_psx *precompose_utf8_readdir(PREC_DIR *prec_dir)
>   		prec_dir->dirent_nfc->d_ino  = res->d_ino;
>   		prec_dir->dirent_nfc->d_type = res->d_type;
>
> -		if ((precomposed_unicode == 1) && has_utf8(res->d_name, (size_t)-1, NULL)) {
> +		if ((precomposed_unicode == 1) && has_non_ascii(res->d_name, (size_t)-1, NULL)) {
>   			if (prec_dir->ic_precompose == (iconv_t)-1) {
>   				die("iconv_open(%s,%s) failed, but needed:\n"
>   						"    precomposed unicode is not supported.\n"
>
Thanks Junio,
that partly obsoletes the patch I'm working on.
And as I didn't manage to catch up, may I send the result of my review?

a) in readdir we die() when iconv_open() fails, and we could/should do 
that in void precompose_argv() as well?

b) Should die("txt") be converted into die(_("txt")) to be able to 
translate the message?

c) We can remove the save/restore of errno at one place, similar to this:


@@ -106,11 +106,8 @@ PREC_DIR *precompose_utf8_opendir(const char *dirname)
                 free(prec_dir->dirent_nfc);
                 free(prec_dir);
                 return NULL;
-       } else {
-               int ret_errno = errno;
+       } else
                 prec_dir->ic_precompose = (iconv_t)-1;
-               errno = ret_errno;
-       }

  reply	other threads:[~2012-08-20 19:52 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-08 13:50 [PATCH v9] git on Mac OS and precomposed unicode Torsten Bögershausen
2012-07-26 20:49 ` Robin Rosenberg
2012-07-26 23:04   ` Junio C Hamano
2012-08-17  3:26     ` Junio C Hamano
2012-08-17 14:53       ` [PATCH] cleanup precompose_utf8 Robin Rosenberg
2012-08-17 17:20         ` Junio C Hamano
2012-08-17 17:30         ` Junio C Hamano
2012-08-19 17:10           ` Torsten Bögershausen
2012-08-20 18:13             ` [PATCH] precompose-utf8: do not call checks for non-ascii "utf8" Junio C Hamano
2012-08-20 19:46               ` Torsten Bögershausen [this message]
2012-08-20 22:02                 ` Junio C Hamano

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

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

  git send-email \
    --in-reply-to=5032940A.4040005@web.de \
    --to=tboegi@web.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=robin.rosenberg@dewire.com \
    /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.
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 NNTP newsgroup(s).