Browse Source

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>
maint
Ævar Arnfjörð Bjarmason 4 years ago committed by Junio C Hamano
parent
commit
a8d5eb6dc0
  1. 5
      combine-diff.c
  2. 26
      diff.c
  3. 7
      diffcore-pickaxe.c
  4. 3
      range-diff.c
  5. 3
      xdiff-interface.c
  6. 2
      xdiff-interface.h

5
combine-diff.c

@ -403,11 +403,11 @@ static void consume_hunk(void *state_,
state->sline[state->nb-1].p_lno[state->n] = state->ob; state->sline[state->nb-1].p_lno[state->n] = state->ob;
} }


static void consume_line(void *state_, char *line, unsigned long len) static int consume_line(void *state_, char *line, unsigned long len)
{ {
struct combine_diff_state *state = state_; struct combine_diff_state *state = state_;
if (!state->lost_bucket) if (!state->lost_bucket)
return; /* not in any hunk yet */ return 0; /* not in any hunk yet */
switch (line[0]) { switch (line[0]) {
case '-': case '-':
append_lost(state->lost_bucket, state->n, line+1, len-1); 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)
state->lno++; state->lno++;
break; break;
} }
return 0;
} }


static void combine_diff(struct repository *r, static void combine_diff(struct repository *r,

26
diff.c

@ -2336,7 +2336,7 @@ static void find_lno(const char *line, struct emit_callback *ecbdata)
ecbdata->lno_in_postimage = strtol(p + 1, NULL, 10); ecbdata->lno_in_postimage = strtol(p + 1, NULL, 10);
} }


static void fn_out_consume(void *priv, char *line, unsigned long len) static int fn_out_consume(void *priv, char *line, unsigned long len)
{ {
struct emit_callback *ecbdata = priv; struct emit_callback *ecbdata = priv;
struct diff_options *o = ecbdata->opt; struct diff_options *o = ecbdata->opt;
@ -2372,7 +2372,7 @@ static void fn_out_consume(void *priv, char *line, unsigned long len)
len = sane_truncate_line(line, len); len = sane_truncate_line(line, len);
find_lno(line, ecbdata); find_lno(line, ecbdata);
emit_hunk_header(ecbdata, line, len); emit_hunk_header(ecbdata, line, len);
return; return 0;
} }


if (ecbdata->diff_words) { if (ecbdata->diff_words) {
@ -2382,11 +2382,11 @@ static void fn_out_consume(void *priv, char *line, unsigned long len)
if (line[0] == '-') { if (line[0] == '-') {
diff_words_append(line, len, diff_words_append(line, len,
&ecbdata->diff_words->minus); &ecbdata->diff_words->minus);
return; return 0;
} else if (line[0] == '+') { } else if (line[0] == '+') {
diff_words_append(line, len, diff_words_append(line, len,
&ecbdata->diff_words->plus); &ecbdata->diff_words->plus);
return; return 0;
} else if (starts_with(line, "\\ ")) { } else if (starts_with(line, "\\ ")) {
/* /*
* Eat the "no newline at eof" marker as if we * 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)
* defer processing. If this is the end of * defer processing. If this is the end of
* preimage, more "+" lines may come after it. * preimage, more "+" lines may come after it.
*/ */
return; return 0;
} }
diff_words_flush(ecbdata); diff_words_flush(ecbdata);
emit_diff_symbol(o, s, line, len, 0); emit_diff_symbol(o, s, line, len, 0);
return; return 0;
} }


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


static void pprint_rename(struct strbuf *name, const char *a, const char *b) 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,
return x; return x;
} }


static void diffstat_consume(void *priv, char *line, unsigned long len) static int diffstat_consume(void *priv, char *line, unsigned long len)
{ {
struct diffstat_t *diffstat = priv; struct diffstat_t *diffstat = priv;
struct diffstat_file *x = diffstat->files[diffstat->nr - 1]; struct diffstat_file *x = diffstat->files[diffstat->nr - 1];
@ -2531,6 +2532,7 @@ static void diffstat_consume(void *priv, char *line, unsigned long len)
x->added++; x->added++;
else if (line[0] == '-') else if (line[0] == '-')
x->deleted++; x->deleted++;
return 0;
} }


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


static void checkdiff_consume(void *priv, char *line, unsigned long len) static int checkdiff_consume(void *priv, char *line, unsigned long len)
{ {
struct checkdiff_t *data = priv; struct checkdiff_t *data = priv;
int marker_size = data->conflict_marker_size; int marker_size = data->conflict_marker_size;
@ -3232,7 +3234,7 @@ static void checkdiff_consume(void *priv, char *line, unsigned long len)
} }
bad = ws_check(line + 1, len - 1, data->ws_rule); bad = ws_check(line + 1, len - 1, data->ws_rule);
if (!bad) if (!bad)
return; return 0;
data->status |= bad; data->status |= bad;
err = whitespace_error_string(bad); err = whitespace_error_string(bad);
fprintf(data->o->file, "%s%s:%d: %s.\n", fprintf(data->o->file, "%s%s:%d: %s.\n",
@ -3244,6 +3246,7 @@ static void checkdiff_consume(void *priv, char *line, unsigned long len)
} else if (line[0] == ' ') { } else if (line[0] == ' ') {
data->lineno++; data->lineno++;
} }
return 0;
} }


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


static void patch_id_consume(void *priv, char *line, unsigned long len) static int patch_id_consume(void *priv, char *line, unsigned long len)
{ {
struct patch_id_t *data = priv; struct patch_id_t *data = priv;
int new_len; int new_len;


if (len > 12 && starts_with(line, "\\ ")) if (len > 12 && starts_with(line, "\\ "))
return; return 0;
new_len = remove_space(line, len); new_len = remove_space(line, len);


the_hash_algo->update_fn(data->ctx, line, new_len); the_hash_algo->update_fn(data->ctx, line, new_len);
data->patchlen += new_len; data->patchlen += new_len;
return 0;
} }


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

7
diffcore-pickaxe.c

@ -19,21 +19,22 @@ struct diffgrep_cb {
int hit; int hit;
}; };


static void diffgrep_consume(void *priv, char *line, unsigned long len) static int diffgrep_consume(void *priv, char *line, unsigned long len)
{ {
struct diffgrep_cb *data = priv; struct diffgrep_cb *data = priv;
regmatch_t regmatch; regmatch_t regmatch;


if (line[0] != '+' && line[0] != '-') if (line[0] != '+' && line[0] != '-')
return; return 0;
if (data->hit) if (data->hit)
/* /*
* NEEDSWORK: we should have a way to terminate the * NEEDSWORK: we should have a way to terminate the
* caller early. * caller early.
*/ */
return; return 0;
data->hit = !regexec_buf(data->regexp, line + 1, len - 1, 1, data->hit = !regexec_buf(data->regexp, line + 1, len - 1, 1,
&regmatch, 0); &regmatch, 0);
return 0;
} }


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

3
range-diff.c

@ -274,9 +274,10 @@ static void find_exact_matches(struct string_list *a, struct string_list *b)
hashmap_clear(&map); hashmap_clear(&map);
} }


static void diffsize_consume(void *data, char *line, unsigned long len) static int diffsize_consume(void *data, char *line, unsigned long len)
{ {
(*(int *)data)++; (*(int *)data)++;
return 0;
} }


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

3
xdiff-interface.c

@ -31,7 +31,7 @@ static int xdiff_out_hunk(void *priv_,
return 0; return 0;
} }


static void consume_one(void *priv_, char *s, unsigned long size) static int consume_one(void *priv_, char *s, unsigned long size)
{ {
struct xdiff_emit_state *priv = priv_; struct xdiff_emit_state *priv = priv_;
char *ep; char *ep;
@ -43,6 +43,7 @@ static void consume_one(void *priv_, char *s, unsigned long size)
size -= this_size; size -= this_size;
s += this_size; s += this_size;
} }
return 0;
} }


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

2
xdiff-interface.h

@ -11,7 +11,7 @@
*/ */
#define MAX_XDIFF_SIZE (1024UL * 1024 * 1023) #define MAX_XDIFF_SIZE (1024UL * 1024 * 1023)


typedef void (*xdiff_emit_line_fn)(void *, char *, unsigned long); typedef int (*xdiff_emit_line_fn)(void *, char *, unsigned long);
typedef void (*xdiff_emit_hunk_fn)(void *data, typedef void (*xdiff_emit_hunk_fn)(void *data,
long old_begin, long old_nr, long old_begin, long old_nr,
long new_begin, long new_nr, long new_begin, long new_nr,

Loading…
Cancel
Save