From mboxrd@z Thu Jan 1 00:00:00 1970 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Subject: [PATCH v4 04/10] grep/icase: avoid kwsset on literal non-ascii strings Date: Fri, 21 Aug 2015 19:47:14 +0700 Message-ID: <1440161240-28554-5-git-send-email-pclouds@gmail.com> References: <1436880280-18194-1-git-send-email-pclouds@gmail.com> <1440161240-28554-1-git-send-email-pclouds@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: QUOTED-PRINTABLE Cc: Junio C Hamano , plamen.totev@abv.bg, l.s.r@web.de, Eric Sunshine , tboegi@web.de, =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= To: git@vger.kernel.org X-From: git-owner@vger.kernel.org Fri Aug 21 14:58:52 2015 Return-path: Envelope-to: gcvg-git-2@plane.gmane.org Received: from vger.kernel.org ([209.132.180.67]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1ZSluF-00042C-Kr for gcvg-git-2@plane.gmane.org; Fri, 21 Aug 2015 14:58:52 +0200 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752903AbbHUM6r convert rfc822-to-quoted-printable (ORCPT ); Fri, 21 Aug 2015 08:58:47 -0400 Received: from mail-pa0-f51.google.com ([209.85.220.51]:33284 "EHLO mail-pa0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752273AbbHUM6q (ORCPT ); Fri, 21 Aug 2015 08:58:46 -0400 Received: by pacgr6 with SMTP id gr6so9357671pac.0 for ; Fri, 21 Aug 2015 05:58:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; bh=T9SIbdfIJZr7FwXgLgX5xFkSCMCjKBex4dYn/kQa1DM=; b=U9evyFbhezCWfJQcHQssVDelZwaTqFvJ+LC7F/p3LZlJTKG6uZMK+V3OUEbfBlVHVn 3r7Nj5uAB/m5ZBcB0qtUzhfjbYBZ+Cgy1HCS7FcAnZpy+kL1PgN0zVqM4x0wz2FwVYqv eh7qN6f01Grn7M97fJQyLbfH0ohhQaSzLM1jXbiDb6hgfAyNXFAgcx5D3Zg356l9I10d HmF9Bry579oJdxHw4E8JpF9TZZM7ajwzhsumuTuGNeG0k27JmEd75YQvGDN2E+Nlxa1z tmfLtM5UJGHiINzQQAuA3cMyCvDaeouVerdAc+3pdnZZDI8cV67DusamQcqlebg8MqIc xCdg== X-Received: by 10.69.2.227 with SMTP id br3mr17330645pbd.9.1440161926215; Fri, 21 Aug 2015 05:58:46 -0700 (PDT) Received: from lanh ([171.232.84.126]) by smtp.gmail.com with ESMTPSA id qb9sm7771465pbb.95.2015.08.21.05.58.42 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Aug 2015 05:58:45 -0700 (PDT) Received: by lanh (sSMTP sendmail emulation); Fri, 21 Aug 2015 19:58:42 +0700 X-Mailer: git-send-email 2.3.0.rc1.137.g477eb31 In-Reply-To: <1440161240-28554-1-git-send-email-pclouds@gmail.com> Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Archived-At: When we detect the pattern is just a literal string, we avoid heavy regex engine and use fast substring search implemented in kwsset.c. But kws uses git-ctype which is locale-independent so it does not know how to fold case properly outside ascii range. Let regcomp or pcre take care of this case instead. Slower, but accurate. Helped-by: Ren=C3=A9 Scharfe Noticed-by: Plamen Totev Signed-off-by: Nguy=E1=BB=85n Th=C3=A1i Ng=E1=BB=8Dc Duy --- grep.c | 7 ++++++- t/t7812-grep-icase-non-ascii.sh (new +x) | 23 +++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100755 t/t7812-grep-icase-non-ascii.sh diff --git a/grep.c b/grep.c index bd32f66..d795b0e 100644 --- a/grep.c +++ b/grep.c @@ -4,6 +4,7 @@ #include "xdiff-interface.h" #include "diff.h" #include "diffcore.h" +#include "commit.h" =20 static int grep_source_load(struct grep_source *gs); static int grep_source_is_binary(struct grep_source *gs); @@ -398,12 +399,16 @@ static int is_fixed(const char *s, size_t len) =20 static void compile_regexp(struct grep_pat *p, struct grep_opt *opt) { + int icase_non_ascii; int err; =20 p->word_regexp =3D opt->word_regexp; p->ignore_case =3D opt->ignore_case; + icase_non_ascii =3D + (opt->regflags & REG_ICASE || p->ignore_case) && + has_non_ascii(p->pattern); =20 - if (is_fixed(p->pattern, p->patternlen)) + if (!icase_non_ascii && is_fixed(p->pattern, p->patternlen)) p->fixed =3D 1; else if (opt->fixed) { p->fixed =3D 1; diff --git a/t/t7812-grep-icase-non-ascii.sh b/t/t7812-grep-icase-non-a= scii.sh new file mode 100755 index 0000000..6eff490 --- /dev/null +++ b/t/t7812-grep-icase-non-ascii.sh @@ -0,0 +1,23 @@ +#!/bin/sh + +test_description=3D'grep icase on non-English locales' + +. ./lib-gettext.sh + +test_expect_success GETTEXT_LOCALE 'setup' ' + printf "TILRAUN: Hall=C3=B3 Heimur!" >file && + git add file && + LC_ALL=3D"$is_IS_locale" && + export LC_ALL +' + +test_have_prereq GETTEXT_LOCALE && +test-regex "HALL=C3=93" "Hall=C3=B3" ICASE && +test_set_prereq REGEX_LOCALE + +test_expect_success REGEX_LOCALE 'grep literal string, no -F' ' + git grep -i "TILRAUN: Hall=C3=B3 Heimur!" && + git grep -i "TILRAUN: HALL=C3=93 HEIMUR!" +' + +test_done --=20 2.3.0.rc1.137.g477eb31