Skip to content

Commit 7dcad2b

Browse files
committed
fixup! Merge branch 'mmap-regexec'
1 parent 790580f commit 7dcad2b

File tree

5 files changed

+20
-57
lines changed

5 files changed

+20
-57
lines changed

diff.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -951,8 +951,7 @@ static int find_word_boundaries(mmfile_t *buffer, regex_t *word_regex,
951951
{
952952
if (word_regex && *begin < buffer->size) {
953953
regmatch_t match[1];
954-
if (!regexec_buf(word_regex, buffer->ptr + *begin,
955-
buffer->size - *begin, 1, match, 0)) {
954+
if (!regexec(word_regex, buffer->ptr + *begin, 1, match, 0)) {
956955
char *p = memchr(buffer->ptr + *begin + match[0].rm_so,
957956
'\n', match[0].rm_eo - match[0].rm_so);
958957
*end = p ? p - buffer->ptr : match[0].rm_eo + *begin;

diffcore-pickaxe.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ static void diffgrep_consume(void *priv, char *line, unsigned long len)
2323
{
2424
struct diffgrep_cb *data = priv;
2525
regmatch_t regmatch;
26+
int hold;
2627

2728
if (line[0] != '+' && line[0] != '-')
2829
return;
@@ -32,8 +33,11 @@ static void diffgrep_consume(void *priv, char *line, unsigned long len)
3233
* caller early.
3334
*/
3435
return;
35-
data->hit = !regexec_buf(data->regexp, line + 1, len - 1, 1,
36-
&regmatch, 0);
36+
/* Yuck -- line ought to be "const char *"! */
37+
hold = line[len];
38+
line[len] = '\0';
39+
data->hit = !regexec(data->regexp, line + 1, 1, &regmatch, 0);
40+
line[len] = hold;
3741
}
3842

3943
static int diff_grep(mmfile_t *one, mmfile_t *two,
@@ -46,11 +50,9 @@ static int diff_grep(mmfile_t *one, mmfile_t *two,
4650
xdemitconf_t xecfg;
4751

4852
if (!one)
49-
return !regexec_buf(regexp, two->ptr, two->size,
50-
1, &regmatch, 0);
53+
return !regexec(regexp, two->ptr, 1, &regmatch, 0);
5154
if (!two)
52-
return !regexec_buf(regexp, one->ptr, one->size,
53-
1, &regmatch, 0);
55+
return !regexec(regexp, one->ptr, 1, &regmatch, 0);
5456

5557
/*
5658
* We have both sides; need to run textual diff and see if
@@ -81,8 +83,8 @@ static unsigned int contains(mmfile_t *mf, regex_t *regexp, kwset_t kws)
8183
regmatch_t regmatch;
8284
int flags = 0;
8385

84-
while (*data &&
85-
!regexec_buf(regexp, data, sz, 1, &regmatch, flags)) {
86+
assert(data[sz] == '\0');
87+
while (*data && !regexec(regexp, data, 1, &regmatch, flags)) {
8688
flags |= REG_NOTBOL;
8789
data += regmatch.rm_eo;
8890
if (*data && regmatch.rm_so == regmatch.rm_eo)

git-compat-util.h

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -983,27 +983,6 @@ void git_qsort(void *base, size_t nmemb, size_t size,
983983
#define qsort git_qsort
984984
#endif
985985

986-
static inline int regexec_buf(const regex_t *preg, const char *buf, size_t size,
987-
size_t nmatch, regmatch_t pmatch[], int eflags)
988-
{
989-
#ifdef REG_STARTEND
990-
assert(nmatch > 0 && pmatch);
991-
pmatch[0].rm_so = 0;
992-
pmatch[0].rm_eo = size;
993-
return regexec(preg, buf, nmatch, pmatch, eflags | REG_STARTEND);
994-
#else
995-
char *buf2 = xmalloc(size + 1);
996-
int ret;
997-
998-
memcpy(buf2, buf, size);
999-
buf2[size] = '\0';
1000-
ret = regexec(preg, buf2, nmatch, pmatch, eflags);
1001-
free(buf2);
1002-
1003-
return ret;
1004-
#endif
1005-
}
1006-
1007986
#ifndef DIR_HAS_BSD_GROUP_SEMANTICS
1008987
# define FORCE_DIR_SET_GID S_ISGID
1009988
#else

t/t4062-diff-pickaxe.sh

Lines changed: 0 additions & 22 deletions
This file was deleted.

xdiff-interface.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,10 +214,11 @@ struct ff_regs {
214214
static long ff_regexp(const char *line, long len,
215215
char *buffer, long buffer_size, void *priv)
216216
{
217+
char *line_buffer;
217218
struct ff_regs *regs = priv;
218219
regmatch_t pmatch[2];
219220
int i;
220-
int result;
221+
int result = -1;
221222

222223
/* Exclude terminating newline (and cr) from matching */
223224
if (len > 0 && line[len-1] == '\n') {
@@ -227,16 +228,18 @@ static long ff_regexp(const char *line, long len,
227228
len--;
228229
}
229230

231+
line_buffer = xstrndup(line, len); /* make NUL terminated */
232+
230233
for (i = 0; i < regs->nr; i++) {
231234
struct ff_reg *reg = regs->array + i;
232-
if (!regexec_buf(&reg->re, line, len, 2, pmatch, 0)) {
235+
if (!regexec(&reg->re, line_buffer, 2, pmatch, 0)) {
233236
if (reg->negate)
234-
return -1;
237+
goto fail;
235238
break;
236239
}
237240
}
238241
if (regs->nr <= i)
239-
return -1;
242+
goto fail;
240243
i = pmatch[1].rm_so >= 0 ? 1 : 0;
241244
line += pmatch[i].rm_so;
242245
result = pmatch[i].rm_eo - pmatch[i].rm_so;
@@ -245,6 +248,8 @@ static long ff_regexp(const char *line, long len,
245248
while (result > 0 && (isspace(line[result - 1])))
246249
result--;
247250
memcpy(buffer, line, result);
251+
fail:
252+
free(line_buffer);
248253
return result;
249254
}
250255

0 commit comments

Comments
 (0)