diffcore-pickaxe: support case insensitive match on non-ascii

Similar to the "grep -F -i" case, we can't use kws on icase search outside ascii range, so we quote the string and pass it to regcomp as a basic regexp and let regex engine deal with case sensitivity. The new test is put in t7812 instead of t4209-log-pickaxe because lib-gettext.sh might cause problems elsewhere, probably. Noticed-by: Plamen Totev <plamen.totev@abv.bg> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nguyễn Thái Ngọc Duy committed Jun 25, 2016 at 07:22 UTC b51a9c1479645b3e0c7d5156d027a97a4bb87977
2 files changed +18
diffcore-pickaxe.c
+11
@@ -7,6 +7,8 @@
7 #include "diffcore.h"
8 #include "xdiff-interface.h"
9 #include "kwset.h"
10 +#include "commit.h"
11 +#include "quote.h"
12
13 typedef int (*pickaxe_fn)(mmfile_t *one, mmfile_t *two,
14 struct diff_options *o,
@@ -223,6 +225,15 @@ void diffcore_pickaxe(struct diff_options *o)
225 cflags |= REG_ICASE;
226 regcomp_or_die(&regex, needle, cflags);
227 regexp = &regex;
228 + } else if (DIFF_OPT_TST(o, PICKAXE_IGNORE_CASE) &&
229 + has_non_ascii(needle)) {
230 + struct strbuf sb = STRBUF_INIT;
231 + int cflags = REG_NEWLINE | REG_ICASE;
232 +
233 + basic_regex_quote_buf(&sb, needle);
234 + regcomp_or_die(&regex, sb.buf, cflags);
235 + strbuf_release(&sb);
236 + regexp = &regex;
237 } else {
238 kws = kwsalloc(DIFF_OPT_TST(o, PICKAXE_IGNORE_CASE)
239 ? tolower_trans_tbl : NULL);
t/t7812-grep-icase-non-ascii.sh
+7
@@ -61,4 +61,11 @@ test_expect_success REGEX_LOCALE 'grep string with regex, with -F' '
61 test_cmp expect2 debug2
62 '
63
64 +test_expect_success REGEX_LOCALE 'pickaxe -i on non-ascii' '
65 + git commit -m first &&
66 + git log --format=%f -i -S"TILRAUN: HALLÓ HEIMUR!" >actual &&
67 + echo first >expected &&
68 + test_cmp expected actual
69 +'
70 +
71 test_done