Skip to content

Commit 4da281e

Browse files
committed
Merge branch 'ab/pickaxe-pcre2'
Rewrite the backend for "diff -G/-S" to use pcre2 engine when available. * ab/pickaxe-pcre2: (22 commits) xdiff-interface: replace discard_hunk_line() with a flag xdiff users: use designated initializers for out_line pickaxe -G: don't special-case create/delete pickaxe -G: terminate early on matching lines xdiff-interface: allow early return from xdiff_emit_line_fn xdiff-interface: prepare for allowing early return pickaxe -S: slightly optimize contains() pickaxe: rename variables in has_changes() for brevity pickaxe -S: support content with NULs under --pickaxe-regex pickaxe: assert that we must have a needle under -G or -S pickaxe: refactor function selection in diffcore-pickaxe() perf: add performance test for pickaxe pickaxe/style: consolidate declarations and assignments diff.h: move pickaxe fields together again pickaxe: die when --find-object and --pickaxe-all are combined pickaxe: die when -G and --pickaxe-regex are combined pickaxe tests: add missing test for --no-pickaxe-regex being an error pickaxe tests: test for -G, -S and --find-object incompatibility pickaxe tests: add test for "log -S" not being a regex pickaxe tests: add test for diffgrep_consume() internals ...
2 parents c9780bb + 5d93460 commit 4da281e

14 files changed

+312
-107
lines changed

builtin/merge-tree.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,12 @@ static void show_diff(struct merge_list *entry)
107107
mmfile_t src, dst;
108108
xpparam_t xpp;
109109
xdemitconf_t xecfg;
110-
xdemitcb_t ecb;
110+
xdemitcb_t ecb = { .out_line = show_outf };
111111

112112
memset(&xpp, 0, sizeof(xpp));
113113
xpp.flags = 0;
114114
memset(&xecfg, 0, sizeof(xecfg));
115115
xecfg.ctxlen = 3;
116-
ecb.out_hunk = NULL;
117-
ecb.out_line = show_outf;
118-
ecb.priv = NULL;
119116

120117
src.ptr = origin(entry, &size);
121118
if (!src.ptr)

builtin/rerere.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ static int diff_two(const char *file1, const char *label1,
2828
{
2929
xpparam_t xpp;
3030
xdemitconf_t xecfg;
31-
xdemitcb_t ecb;
31+
xdemitcb_t ecb = { .out_line = outf };
3232
mmfile_t minus, plus;
3333
int ret;
3434

@@ -41,8 +41,6 @@ static int diff_two(const char *file1, const char *label1,
4141
xpp.flags = 0;
4242
memset(&xecfg, 0, sizeof(xecfg));
4343
xecfg.ctxlen = 3;
44-
ecb.out_hunk = NULL;
45-
ecb.out_line = outf;
4644
ret = xdi_diff(&minus, &plus, &xpp, &xecfg, &ecb);
4745

4846
free(minus.ptr);

combine-diff.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -403,11 +403,11 @@ static void consume_hunk(void *state_,
403403
state->sline[state->nb-1].p_lno[state->n] = state->ob;
404404
}
405405

406-
static void consume_line(void *state_, char *line, unsigned long len)
406+
static int consume_line(void *state_, char *line, unsigned long len)
407407
{
408408
struct combine_diff_state *state = state_;
409409
if (!state->lost_bucket)
410-
return; /* not in any hunk yet */
410+
return 0; /* not in any hunk yet */
411411
switch (line[0]) {
412412
case '-':
413413
append_lost(state->lost_bucket, state->n, line+1, len-1);
@@ -417,6 +417,7 @@ static void consume_line(void *state_, char *line, unsigned long len)
417417
state->lno++;
418418
break;
419419
}
420+
return 0;
420421
}
421422

422423
static void combine_diff(struct repository *r,

diff.c

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2340,7 +2340,7 @@ static void find_lno(const char *line, struct emit_callback *ecbdata)
23402340
ecbdata->lno_in_postimage = strtol(p + 1, NULL, 10);
23412341
}
23422342

2343-
static void fn_out_consume(void *priv, char *line, unsigned long len)
2343+
static int fn_out_consume(void *priv, char *line, unsigned long len)
23442344
{
23452345
struct emit_callback *ecbdata = priv;
23462346
struct diff_options *o = ecbdata->opt;
@@ -2376,7 +2376,7 @@ static void fn_out_consume(void *priv, char *line, unsigned long len)
23762376
len = sane_truncate_line(line, len);
23772377
find_lno(line, ecbdata);
23782378
emit_hunk_header(ecbdata, line, len);
2379-
return;
2379+
return 0;
23802380
}
23812381

23822382
if (ecbdata->diff_words) {
@@ -2386,11 +2386,11 @@ static void fn_out_consume(void *priv, char *line, unsigned long len)
23862386
if (line[0] == '-') {
23872387
diff_words_append(line, len,
23882388
&ecbdata->diff_words->minus);
2389-
return;
2389+
return 0;
23902390
} else if (line[0] == '+') {
23912391
diff_words_append(line, len,
23922392
&ecbdata->diff_words->plus);
2393-
return;
2393+
return 0;
23942394
} else if (starts_with(line, "\\ ")) {
23952395
/*
23962396
* Eat the "no newline at eof" marker as if we
@@ -2399,11 +2399,11 @@ static void fn_out_consume(void *priv, char *line, unsigned long len)
23992399
* defer processing. If this is the end of
24002400
* preimage, more "+" lines may come after it.
24012401
*/
2402-
return;
2402+
return 0;
24032403
}
24042404
diff_words_flush(ecbdata);
24052405
emit_diff_symbol(o, s, line, len, 0);
2406-
return;
2406+
return 0;
24072407
}
24082408

24092409
switch (line[0]) {
@@ -2427,6 +2427,7 @@ static void fn_out_consume(void *priv, char *line, unsigned long len)
24272427
line, len, 0);
24282428
break;
24292429
}
2430+
return 0;
24302431
}
24312432

24322433
static void pprint_rename(struct strbuf *name, const char *a, const char *b)
@@ -2526,7 +2527,7 @@ static struct diffstat_file *diffstat_add(struct diffstat_t *diffstat,
25262527
return x;
25272528
}
25282529

2529-
static void diffstat_consume(void *priv, char *line, unsigned long len)
2530+
static int diffstat_consume(void *priv, char *line, unsigned long len)
25302531
{
25312532
struct diffstat_t *diffstat = priv;
25322533
struct diffstat_file *x = diffstat->files[diffstat->nr - 1];
@@ -2535,6 +2536,7 @@ static void diffstat_consume(void *priv, char *line, unsigned long len)
25352536
x->added++;
25362537
else if (line[0] == '-')
25372538
x->deleted++;
2539+
return 0;
25382540
}
25392541

25402542
const char mime_boundary_leader[] = "------------";
@@ -3212,7 +3214,7 @@ static void checkdiff_consume_hunk(void *priv,
32123214
data->lineno = nb - 1;
32133215
}
32143216

3215-
static void checkdiff_consume(void *priv, char *line, unsigned long len)
3217+
static int checkdiff_consume(void *priv, char *line, unsigned long len)
32163218
{
32173219
struct checkdiff_t *data = priv;
32183220
int marker_size = data->conflict_marker_size;
@@ -3236,7 +3238,7 @@ static void checkdiff_consume(void *priv, char *line, unsigned long len)
32363238
}
32373239
bad = ws_check(line + 1, len - 1, data->ws_rule);
32383240
if (!bad)
3239-
return;
3241+
return 0;
32403242
data->status |= bad;
32413243
err = whitespace_error_string(bad);
32423244
fprintf(data->o->file, "%s%s:%d: %s.\n",
@@ -3248,6 +3250,7 @@ static void checkdiff_consume(void *priv, char *line, unsigned long len)
32483250
} else if (line[0] == ' ') {
32493251
data->lineno++;
32503252
}
3253+
return 0;
32513254
}
32523255

32533256
static unsigned char *deflate_it(char *data,
@@ -3726,7 +3729,8 @@ static void builtin_diffstat(const char *name_a, const char *name_b,
37263729
xpp.anchors_nr = o->anchors_nr;
37273730
xecfg.ctxlen = o->context;
37283731
xecfg.interhunkctxlen = o->interhunkcontext;
3729-
if (xdi_diff_outf(&mf1, &mf2, discard_hunk_line,
3732+
xecfg.flags = XDL_EMIT_NO_HUNK_HDR;
3733+
if (xdi_diff_outf(&mf1, &mf2, NULL,
37303734
diffstat_consume, diffstat, &xpp, &xecfg))
37313735
die("unable to generate diffstat for %s", one->path);
37323736

@@ -4632,6 +4636,12 @@ void diff_setup_done(struct diff_options *options)
46324636
if (HAS_MULTI_BITS(options->pickaxe_opts & DIFF_PICKAXE_KINDS_MASK))
46334637
die(_("-G, -S and --find-object are mutually exclusive"));
46344638

4639+
if (HAS_MULTI_BITS(options->pickaxe_opts & DIFF_PICKAXE_KINDS_G_REGEX_MASK))
4640+
die(_("-G and --pickaxe-regex are mutually exclusive, use --pickaxe-regex with -S"));
4641+
4642+
if (HAS_MULTI_BITS(options->pickaxe_opts & DIFF_PICKAXE_KINDS_ALL_OBJFIND_MASK))
4643+
die(_("---pickaxe-all and --find-object are mutually exclusive, use --pickaxe-all with -G and -S"));
4644+
46354645
/*
46364646
* Most of the time we can say "there are changes"
46374647
* only by checking if there are changed paths, but
@@ -6119,17 +6129,18 @@ void flush_one_hunk(struct object_id *result, git_hash_ctx *ctx)
61196129
}
61206130
}
61216131

6122-
static void patch_id_consume(void *priv, char *line, unsigned long len)
6132+
static int patch_id_consume(void *priv, char *line, unsigned long len)
61236133
{
61246134
struct patch_id_t *data = priv;
61256135
int new_len;
61266136

61276137
if (len > 12 && starts_with(line, "\\ "))
6128-
return;
6138+
return 0;
61296139
new_len = remove_space(line, len);
61306140

61316141
the_hash_algo->update_fn(data->ctx, line, new_len);
61326142
data->patchlen += new_len;
6143+
return 0;
61336144
}
61346145

61356146
static void patch_id_add_string(git_hash_ctx *ctx, const char *str)
@@ -6227,8 +6238,8 @@ static int diff_get_patch_id(struct diff_options *options, struct object_id *oid
62276238

62286239
xpp.flags = 0;
62296240
xecfg.ctxlen = 3;
6230-
xecfg.flags = 0;
6231-
if (xdi_diff_outf(&mf1, &mf2, discard_hunk_line,
6241+
xecfg.flags = XDL_EMIT_NO_HUNK_HDR;
6242+
if (xdi_diff_outf(&mf1, &mf2, NULL,
62326243
patch_id_consume, &data, &xpp, &xecfg))
62336244
return error("unable to generate patch-id diff for %s",
62346245
p->one->path);

diff.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ struct diff_options {
265265
* postimage of the diff_queue.
266266
*/
267267
const char *pickaxe;
268+
unsigned pickaxe_opts;
268269

269270
/* -I<regex> */
270271
regex_t **ignore_regex;
@@ -304,8 +305,6 @@ struct diff_options {
304305
/* The output format used when `diff_flush()` is run. */
305306
int output_format;
306307

307-
unsigned pickaxe_opts;
308-
309308
/* Affects the way detection logic for complete rewrites, renames and
310309
* copies.
311310
*/
@@ -556,6 +555,10 @@ int git_config_rename(const char *var, const char *value);
556555
#define DIFF_PICKAXE_KINDS_MASK (DIFF_PICKAXE_KIND_S | \
557556
DIFF_PICKAXE_KIND_G | \
558557
DIFF_PICKAXE_KIND_OBJFIND)
558+
#define DIFF_PICKAXE_KINDS_G_REGEX_MASK (DIFF_PICKAXE_KIND_G | \
559+
DIFF_PICKAXE_REGEX)
560+
#define DIFF_PICKAXE_KINDS_ALL_OBJFIND_MASK (DIFF_PICKAXE_ALL | \
561+
DIFF_PICKAXE_KIND_OBJFIND)
559562

560563
#define DIFF_PICKAXE_IGNORE_CASE 32
561564

0 commit comments

Comments
 (0)