xdiff-interface: prepare for allowing early return

Change the function prototype of xdiff_emit_line_fn to return an "int" instead of "void". Change all of those functions to "return 0", nothing checks those return values yet, and no behavior is being changed. In subsequent commits the interface will be changed to allow early return via this new return value. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ævar Arnfjörð Bjarmason committed Apr 12, 2021 at 19:15 UTC a8d5eb6dc0d61625667b0d8155c425d3629baa12
6 files changed +27 -19
combine-diff.c
+3 -2
@@ -403,11 +403,11 @@ static void consume_hunk(void *state_,
403 state->sline[state->nb-1].p_lno[state->n] = state->ob;
404 }
405
406 -static void consume_line(void *state_, char *line, unsigned long len)
406 +static int consume_line(void *state_, char *line, unsigned long len)
407 {
408 struct combine_diff_state *state = state_;
409 if (!state->lost_bucket)
410 - return; /* not in any hunk yet */
410 + return 0; /* not in any hunk yet */
411 switch (line[0]) {
412 case '-':
413 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)
417 state->lno++;
418 break;
419 }
420 + return 0;
421 }
422
423 static void combine_diff(struct repository *r,
diff.c
+15 -11
@@ -2336,7 +2336,7 @@ static void find_lno(const char *line, struct emit_callback *ecbdata)
2336 ecbdata->lno_in_postimage = strtol(p + 1, NULL, 10);
2337 }
2338
2339 -static void fn_out_consume(void *priv, char *line, unsigned long len)
2339 +static int fn_out_consume(void *priv, char *line, unsigned long len)
2340 {
2341 struct emit_callback *ecbdata = priv;
2342 struct diff_options *o = ecbdata->opt;
@@ -2372,7 +2372,7 @@ static void fn_out_consume(void *priv, char *line, unsigned long len)
2372 len = sane_truncate_line(line, len);
2373 find_lno(line, ecbdata);
2374 emit_hunk_header(ecbdata, line, len);
2375 - return;
2375 + return 0;
2376 }
2377
2378 if (ecbdata->diff_words) {
@@ -2382,11 +2382,11 @@ static void fn_out_consume(void *priv, char *line, unsigned long len)
2382 if (line[0] == '-') {
2383 diff_words_append(line, len,
2384 &ecbdata->diff_words->minus);
2385 - return;
2385 + return 0;
2386 } else if (line[0] == '+') {
2387 diff_words_append(line, len,
2388 &ecbdata->diff_words->plus);
2389 - return;
2389 + return 0;
2390 } else if (starts_with(line, "\\ ")) {
2391 /*
2392 * Eat the "no newline at eof" marker as if we
@@ -2395,11 +2395,11 @@ static void fn_out_consume(void *priv, char *line, unsigned long len)
2395 * defer processing. If this is the end of
2396 * preimage, more "+" lines may come after it.
2397 */
2398 - return;
2398 + return 0;
2399 }
2400 diff_words_flush(ecbdata);
2401 emit_diff_symbol(o, s, line, len, 0);
2402 - return;
2402 + return 0;
2403 }
2404
2405 switch (line[0]) {
@@ -2423,6 +2423,7 @@ static void fn_out_consume(void *priv, char *line, unsigned long len)
2423 line, len, 0);
2424 break;
2425 }
2426 + return 0;
2427 }
2428
2429 static void pprint_rename(struct strbuf *name, const char *a, const char *b)
@@ -2522,7 +2523,7 @@ static struct diffstat_file *diffstat_add(struct diffstat_t *diffstat,
2523 return x;
2524 }
2525
2525 -static void diffstat_consume(void *priv, char *line, unsigned long len)
2526 +static int diffstat_consume(void *priv, char *line, unsigned long len)
2527 {
2528 struct diffstat_t *diffstat = priv;
2529 struct diffstat_file *x = diffstat->files[diffstat->nr - 1];
@@ -2531,6 +2532,7 @@ static void diffstat_consume(void *priv, char *line, unsigned long len)
2532 x->added++;
2533 else if (line[0] == '-')
2534 x->deleted++;
2535 + return 0;
2536 }
2537
2538 const char mime_boundary_leader[] = "------------";
@@ -3208,7 +3210,7 @@ static void checkdiff_consume_hunk(void *priv,
3210 data->lineno = nb - 1;
3211 }
3212
3211 -static void checkdiff_consume(void *priv, char *line, unsigned long len)
3213 +static int checkdiff_consume(void *priv, char *line, unsigned long len)
3214 {
3215 struct checkdiff_t *data = priv;
3216 int marker_size = data->conflict_marker_size;
@@ -3232,7 +3234,7 @@ static void checkdiff_consume(void *priv, char *line, unsigned long len)
3234 }
3235 bad = ws_check(line + 1, len - 1, data->ws_rule);
3236 if (!bad)
3235 - return;
3237 + return 0;
3238 data->status |= bad;
3239 err = whitespace_error_string(bad);
3240 fprintf(data->o->file, "%s%s:%d: %s.\n",
@@ -3244,6 +3246,7 @@ static void checkdiff_consume(void *priv, char *line, unsigned long len)
3246 } else if (line[0] == ' ') {
3247 data->lineno++;
3248 }
3249 + return 0;
3250 }
3251
3252 static unsigned char *deflate_it(char *data,
@@ -6121,17 +6124,18 @@ void flush_one_hunk(struct object_id *result, git_hash_ctx *ctx)
6124 }
6125 }
6126
6124 -static void patch_id_consume(void *priv, char *line, unsigned long len)
6127 +static int patch_id_consume(void *priv, char *line, unsigned long len)
6128 {
6129 struct patch_id_t *data = priv;
6130 int new_len;
6131
6132 if (len > 12 && starts_with(line, "\\ "))
6130 - return;
6133 + return 0;
6134 new_len = remove_space(line, len);
6135
6136 the_hash_algo->update_fn(data->ctx, line, new_len);
6137 data->patchlen += new_len;
6138 + return 0;
6139 }
6140
6141 static void patch_id_add_string(git_hash_ctx *ctx, const char *str)
diffcore-pickaxe.c
+4 -3
@@ -19,21 +19,22 @@ struct diffgrep_cb {
19 int hit;
20 };
21
22 -static void diffgrep_consume(void *priv, char *line, unsigned long len)
22 +static int diffgrep_consume(void *priv, char *line, unsigned long len)
23 {
24 struct diffgrep_cb *data = priv;
25 regmatch_t regmatch;
26
27 if (line[0] != '+' && line[0] != '-')
28 - return;
28 + return 0;
29 if (data->hit)
30 /*
31 * NEEDSWORK: we should have a way to terminate the
32 * caller early.
33 */
34 - return;
34 + return 0;
35 data->hit = !regexec_buf(data->regexp, line + 1, len - 1, 1,
36 &regmatch, 0);
37 + return 0;
38 }
39
40 static int diff_grep(mmfile_t *one, mmfile_t *two,
range-diff.c
+2 -1
@@ -274,9 +274,10 @@ static void find_exact_matches(struct string_list *a, struct string_list *b)
274 hashmap_clear(&map);
275 }
276
277 -static void diffsize_consume(void *data, char *line, unsigned long len)
277 +static int diffsize_consume(void *data, char *line, unsigned long len)
278 {
279 (*(int *)data)++;
280 + return 0;
281 }
282
283 static void diffsize_hunk(void *data, long ob, long on, long nb, long nn,
xdiff-interface.c
+2 -1
@@ -31,7 +31,7 @@ static int xdiff_out_hunk(void *priv_,
31 return 0;
32 }
33
34 -static void consume_one(void *priv_, char *s, unsigned long size)
34 +static int consume_one(void *priv_, char *s, unsigned long size)
35 {
36 struct xdiff_emit_state *priv = priv_;
37 char *ep;
@@ -43,6 +43,7 @@ static void consume_one(void *priv_, char *s, unsigned long size)
43 size -= this_size;
44 s += this_size;
45 }
46 + return 0;
47 }
48
49 static int xdiff_outf(void *priv_, mmbuffer_t *mb, int nbuf)
xdiff-interface.h
+1 -1
@@ -11,7 +11,7 @@
11 */
12 #define MAX_XDIFF_SIZE (1024UL * 1024 * 1023)
13
14 -typedef void (*xdiff_emit_line_fn)(void *, char *, unsigned long);
14 +typedef int (*xdiff_emit_line_fn)(void *, char *, unsigned long);
15 typedef void (*xdiff_emit_hunk_fn)(void *data,
16 long old_begin, long old_nr,
17 long new_begin, long new_nr,