diffcore-pickaxe: support case insensitive match on non-ascii
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>
Sat, 25 Jun 2016 05:22:37 +0000 (07:22 +0200)
committerJunio C Hamano <gitster@pobox.com>
Fri, 1 Jul 2016 19:44:57 +0000 (12:44 -0700)
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>
diffcore-pickaxe.c
t/t7812-grep-icase-non-ascii.sh
index 2093b6ab75c6348c50b016d6a157c66d733ff747..55067cab6c2dbfb6abbfffa0aa9d7259502041cb 100644 (file)
@@ -7,6 +7,8 @@
 #include "diffcore.h"
 #include "xdiff-interface.h"
 #include "kwset.h"
+#include "commit.h"
+#include "quote.h"
 
 typedef int (*pickaxe_fn)(mmfile_t *one, mmfile_t *two,
                          struct diff_options *o,
@@ -223,6 +225,15 @@ void diffcore_pickaxe(struct diff_options *o)
                        cflags |= REG_ICASE;
                regcomp_or_die(&regex, needle, cflags);
                regexp = &regex;
+       } else if (DIFF_OPT_TST(o, PICKAXE_IGNORE_CASE) &&
+                  has_non_ascii(needle)) {
+               struct strbuf sb = STRBUF_INIT;
+               int cflags = REG_NEWLINE | REG_ICASE;
+
+               basic_regex_quote_buf(&sb, needle);
+               regcomp_or_die(&regex, sb.buf, cflags);
+               strbuf_release(&sb);
+               regexp = &regex;
        } else {
                kws = kwsalloc(DIFF_OPT_TST(o, PICKAXE_IGNORE_CASE)
                               ? tolower_trans_tbl : NULL);
index 08ae4c945dee967a20bb8306938dc9ba721a9f18..169fd8d7065f89ce78f5241eeb7bf376c3f3172d 100755 (executable)
@@ -61,4 +61,11 @@ test_expect_success REGEX_LOCALE 'grep string with regex, with -F' '
        test_cmp expect2 debug2
 '
 
+test_expect_success REGEX_LOCALE 'pickaxe -i on non-ascii' '
+       git commit -m first &&
+       git log --format=%f -i -S"TILRAUN: HALLÓ HEIMUR!" >actual &&
+       echo first >expected &&
+       test_cmp expected actual
+'
+
 test_done