diff options
Diffstat (limited to 'combine-diff.c')
-rw-r--r-- | combine-diff.c | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/combine-diff.c b/combine-diff.c index 9228aebc16..d93782daeb 100644 --- a/combine-diff.c +++ b/combine-diff.c @@ -214,11 +214,11 @@ static struct lline *coalesce_lines(struct lline *base, int *lenbase, * - Else if we have NEW, insert newend lline into base and * consume newend */ - lcs = xcalloc(st_add(origbaselen, 1), sizeof(int*)); - directions = xcalloc(st_add(origbaselen, 1), sizeof(enum coalesce_direction*)); + CALLOC_ARRAY(lcs, st_add(origbaselen, 1)); + CALLOC_ARRAY(directions, st_add(origbaselen, 1)); for (i = 0; i < origbaselen + 1; i++) { - lcs[i] = xcalloc(st_add(lennew, 1), sizeof(int)); - directions[i] = xcalloc(st_add(lennew, 1), sizeof(enum coalesce_direction)); + CALLOC_ARRAY(lcs[i], st_add(lennew, 1)); + CALLOC_ARRAY(directions[i], st_add(lennew, 1)); directions[i][0] = BASE; } for (j = 1; j < lennew + 1; j++) @@ -398,16 +398,16 @@ static void consume_hunk(void *state_, state->lost_bucket = &state->sline[state->nb-1]; } if (!state->sline[state->nb-1].p_lno) - state->sline[state->nb-1].p_lno = - xcalloc(state->num_parent, sizeof(unsigned long)); + CALLOC_ARRAY(state->sline[state->nb - 1].p_lno, + state->num_parent); 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_; if (!state->lost_bucket) - return; /* not in any hunk yet */ + return 0; /* not in any hunk yet */ switch (line[0]) { case '-': 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++; break; } + return 0; } static void combine_diff(struct repository *r, @@ -1068,7 +1069,7 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent, &result_size, NULL, NULL); } else if (textconv) { struct diff_filespec *df = alloc_filespec(elem->path); - fill_filespec(df, &null_oid, 0, st.st_mode); + fill_filespec(df, null_oid(), 0, st.st_mode); result_size = fill_textconv(opt->repo, textconv, df, &result); free_filespec(df); } else if (0 <= (fd = open(elem->path, O_RDONLY))) { @@ -1159,7 +1160,7 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent, if (result_size && result[result_size-1] != '\n') cnt++; /* incomplete line */ - sline = xcalloc(st_add(cnt, 2), sizeof(*sline)); + CALLOC_ARRAY(sline, st_add(cnt, 2)); sline[0].bol = result; for (lno = 0, cp = result; cp < result + result_size; cp++) { if (*cp == '\n') { @@ -1178,7 +1179,7 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent, /* Even p_lno[cnt+1] is valid -- that is for the end line number * for deletion hunk at the end. */ - sline[0].p_lno = xcalloc(st_mult(st_add(cnt, 2), num_parent), sizeof(unsigned long)); + CALLOC_ARRAY(sline[0].p_lno, st_mult(st_add(cnt, 2), num_parent)); for (lno = 0; lno <= cnt; lno++) sline[lno+1].p_lno = sline[lno].p_lno + num_parent; @@ -1319,7 +1320,7 @@ static struct diff_filepair *combined_pair(struct combine_diff_path *p, struct diff_filespec *pool; pair = xmalloc(sizeof(*pair)); - pool = xcalloc(st_add(num_parent, 1), sizeof(struct diff_filespec)); + CALLOC_ARRAY(pool, st_add(num_parent, 1)); pair->one = pool + 1; pair->two = pool; @@ -1348,7 +1349,7 @@ static void handle_combined_callback(struct diff_options *opt, struct diff_queue_struct q; int i; - q.queue = xcalloc(num_paths, sizeof(struct diff_filepair *)); + CALLOC_ARRAY(q.queue, num_paths); q.alloc = num_paths; q.nr = num_paths; for (i = 0, p = paths; p; p = p->next) |