Skip to content

Commit b51a9c1

Browse files
pcloudsgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3d5b23a commit b51a9c1

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

diffcore-pickaxe.c

+11
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#include "diffcore.h"
88
#include "xdiff-interface.h"
99
#include "kwset.h"
10+
#include "commit.h"
11+
#include "quote.h"
1012

1113
typedef int (*pickaxe_fn)(mmfile_t *one, mmfile_t *two,
1214
struct diff_options *o,
@@ -223,6 +225,15 @@ void diffcore_pickaxe(struct diff_options *o)
223225
cflags |= REG_ICASE;
224226
regcomp_or_die(&regex, needle, cflags);
225227
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;
226237
} else {
227238
kws = kwsalloc(DIFF_OPT_TST(o, PICKAXE_IGNORE_CASE)
228239
? tolower_trans_tbl : NULL);

t/t7812-grep-icase-non-ascii.sh

+7
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,11 @@ test_expect_success REGEX_LOCALE 'grep string with regex, with -F' '
6161
test_cmp expect2 debug2
6262
'
6363

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+
6471
test_done

0 commit comments

Comments
 (0)