Skip to content

Commit a8d5eb6

Browse files
avargitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5b0672a commit a8d5eb6

File tree

6 files changed

+27
-19
lines changed

6 files changed

+27
-19
lines changed

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: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2336,7 +2336,7 @@ static void find_lno(const char *line, struct emit_callback *ecbdata)
23362336
ecbdata->lno_in_postimage = strtol(p + 1, NULL, 10);
23372337
}
23382338

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)
23402340
{
23412341
struct emit_callback *ecbdata = priv;
23422342
struct diff_options *o = ecbdata->opt;
@@ -2372,7 +2372,7 @@ static void fn_out_consume(void *priv, char *line, unsigned long len)
23722372
len = sane_truncate_line(line, len);
23732373
find_lno(line, ecbdata);
23742374
emit_hunk_header(ecbdata, line, len);
2375-
return;
2375+
return 0;
23762376
}
23772377

23782378
if (ecbdata->diff_words) {
@@ -2382,11 +2382,11 @@ static void fn_out_consume(void *priv, char *line, unsigned long len)
23822382
if (line[0] == '-') {
23832383
diff_words_append(line, len,
23842384
&ecbdata->diff_words->minus);
2385-
return;
2385+
return 0;
23862386
} else if (line[0] == '+') {
23872387
diff_words_append(line, len,
23882388
&ecbdata->diff_words->plus);
2389-
return;
2389+
return 0;
23902390
} else if (starts_with(line, "\\ ")) {
23912391
/*
23922392
* 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)
23952395
* defer processing. If this is the end of
23962396
* preimage, more "+" lines may come after it.
23972397
*/
2398-
return;
2398+
return 0;
23992399
}
24002400
diff_words_flush(ecbdata);
24012401
emit_diff_symbol(o, s, line, len, 0);
2402-
return;
2402+
return 0;
24032403
}
24042404

24052405
switch (line[0]) {
@@ -2423,6 +2423,7 @@ static void fn_out_consume(void *priv, char *line, unsigned long len)
24232423
line, len, 0);
24242424
break;
24252425
}
2426+
return 0;
24262427
}
24272428

24282429
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,
25222523
return x;
25232524
}
25242525

2525-
static void diffstat_consume(void *priv, char *line, unsigned long len)
2526+
static int diffstat_consume(void *priv, char *line, unsigned long len)
25262527
{
25272528
struct diffstat_t *diffstat = priv;
25282529
struct diffstat_file *x = diffstat->files[diffstat->nr - 1];
@@ -2531,6 +2532,7 @@ static void diffstat_consume(void *priv, char *line, unsigned long len)
25312532
x->added++;
25322533
else if (line[0] == '-')
25332534
x->deleted++;
2535+
return 0;
25342536
}
25352537

25362538
const char mime_boundary_leader[] = "------------";
@@ -3208,7 +3210,7 @@ static void checkdiff_consume_hunk(void *priv,
32083210
data->lineno = nb - 1;
32093211
}
32103212

3211-
static void checkdiff_consume(void *priv, char *line, unsigned long len)
3213+
static int checkdiff_consume(void *priv, char *line, unsigned long len)
32123214
{
32133215
struct checkdiff_t *data = priv;
32143216
int marker_size = data->conflict_marker_size;
@@ -3232,7 +3234,7 @@ static void checkdiff_consume(void *priv, char *line, unsigned long len)
32323234
}
32333235
bad = ws_check(line + 1, len - 1, data->ws_rule);
32343236
if (!bad)
3235-
return;
3237+
return 0;
32363238
data->status |= bad;
32373239
err = whitespace_error_string(bad);
32383240
fprintf(data->o->file, "%s%s:%d: %s.\n",
@@ -3244,6 +3246,7 @@ static void checkdiff_consume(void *priv, char *line, unsigned long len)
32443246
} else if (line[0] == ' ') {
32453247
data->lineno++;
32463248
}
3249+
return 0;
32473250
}
32483251

32493252
static unsigned char *deflate_it(char *data,
@@ -6121,17 +6124,18 @@ void flush_one_hunk(struct object_id *result, git_hash_ctx *ctx)
61216124
}
61226125
}
61236126

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)
61256128
{
61266129
struct patch_id_t *data = priv;
61276130
int new_len;
61286131

61296132
if (len > 12 && starts_with(line, "\\ "))
6130-
return;
6133+
return 0;
61316134
new_len = remove_space(line, len);
61326135

61336136
the_hash_algo->update_fn(data->ctx, line, new_len);
61346137
data->patchlen += new_len;
6138+
return 0;
61356139
}
61366140

61376141
static void patch_id_add_string(git_hash_ctx *ctx, const char *str)

diffcore-pickaxe.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,22 @@ struct diffgrep_cb {
1919
int hit;
2020
};
2121

22-
static void diffgrep_consume(void *priv, char *line, unsigned long len)
22+
static int diffgrep_consume(void *priv, char *line, unsigned long len)
2323
{
2424
struct diffgrep_cb *data = priv;
2525
regmatch_t regmatch;
2626

2727
if (line[0] != '+' && line[0] != '-')
28-
return;
28+
return 0;
2929
if (data->hit)
3030
/*
3131
* NEEDSWORK: we should have a way to terminate the
3232
* caller early.
3333
*/
34-
return;
34+
return 0;
3535
data->hit = !regexec_buf(data->regexp, line + 1, len - 1, 1,
3636
&regmatch, 0);
37+
return 0;
3738
}
3839

3940
static int diff_grep(mmfile_t *one, mmfile_t *two,

range-diff.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,9 +274,10 @@ static void find_exact_matches(struct string_list *a, struct string_list *b)
274274
hashmap_clear(&map);
275275
}
276276

277-
static void diffsize_consume(void *data, char *line, unsigned long len)
277+
static int diffsize_consume(void *data, char *line, unsigned long len)
278278
{
279279
(*(int *)data)++;
280+
return 0;
280281
}
281282

282283
static void diffsize_hunk(void *data, long ob, long on, long nb, long nn,

xdiff-interface.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ static int xdiff_out_hunk(void *priv_,
3131
return 0;
3232
}
3333

34-
static void consume_one(void *priv_, char *s, unsigned long size)
34+
static int consume_one(void *priv_, char *s, unsigned long size)
3535
{
3636
struct xdiff_emit_state *priv = priv_;
3737
char *ep;
@@ -43,6 +43,7 @@ static void consume_one(void *priv_, char *s, unsigned long size)
4343
size -= this_size;
4444
s += this_size;
4545
}
46+
return 0;
4647
}
4748

4849
static int xdiff_outf(void *priv_, mmbuffer_t *mb, int nbuf)

xdiff-interface.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*/
1212
#define MAX_XDIFF_SIZE (1024UL * 1024 * 1023)
1313

14-
typedef void (*xdiff_emit_line_fn)(void *, char *, unsigned long);
14+
typedef int (*xdiff_emit_line_fn)(void *, char *, unsigned long);
1515
typedef void (*xdiff_emit_hunk_fn)(void *data,
1616
long old_begin, long old_nr,
1717
long new_begin, long new_nr,

0 commit comments

Comments
 (0)