summaryrefslogtreecommitdiff
path: root/grep.c
diff options
context:
space:
mode:
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>2016-06-25 07:22:30 +0200
committerJunio C Hamano <gitster@pobox.com>2016-06-27 07:31:35 -0700
commit5c1ebcca4d1df3b2a84d01b3f32ec13bf8f760f8 (patch)
treeb3ae3c96fcc407dad3de84c7c4d29ca2447bc426 /grep.c
parentd8acfe1eaf8621025c4095d3fbb88b2703b3fa54 (diff)
downloadgit-5c1ebcca4d1df3b2a84d01b3f32ec13bf8f760f8.tar.gz
grep/icase: avoid kwsset on literal non-ascii strings
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. Noticed-by: Plamen Totev <plamen.totev@abv.bg> Helped-by: René Scharfe <l.s.r@web.de> Helped-by: Eric Sunshine <sunshine@sunshineco.com> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'grep.c')
-rw-r--r--grep.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/grep.c b/grep.c
index f430d7e756..451275d298 100644
--- a/grep.c
+++ b/grep.c
@@ -4,6 +4,7 @@
#include "xdiff-interface.h"
#include "diff.h"
#include "diffcore.h"
+#include "commit.h"
static int grep_source_load(struct grep_source *gs);
static int grep_source_is_binary(struct grep_source *gs);
@@ -398,14 +399,18 @@ static int is_fixed(const char *s, size_t len)
static void compile_regexp(struct grep_pat *p, struct grep_opt *opt)
{
+ int icase, ascii_only;
int err;
p->word_regexp = opt->word_regexp;
p->ignore_case = opt->ignore_case;
+ icase = opt->regflags & REG_ICASE || p->ignore_case;
+ ascii_only = !has_non_ascii(p->pattern);
if (opt->fixed)
p->fixed = 1;
- else if (is_fixed(p->pattern, p->patternlen))
+ else if ((!icase || ascii_only) &&
+ is_fixed(p->pattern, p->patternlen))
p->fixed = 1;
else
p->fixed = 0;