combine-diff: use an xdiff hunk callback
A combined diff has to line up the hunks for all of the individual pairwise diffs, and thus needs to know their line numbers and sizes. We get that now by parsing the hunk header line that xdiff generates. However, now that xdiff supports a hunk callback, we can just use the values directly. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
7c61e25fbf
commit
0074c9110d
@ -344,38 +344,43 @@ struct combine_diff_state {
|
||||
struct sline *lost_bucket;
|
||||
};
|
||||
|
||||
static void consume_hunk(void *state_,
|
||||
long ob, long on,
|
||||
long nb, long nn,
|
||||
const char *funcline, long funclen)
|
||||
{
|
||||
struct combine_diff_state *state = state_;
|
||||
|
||||
state->ob = ob;
|
||||
state->on = on;
|
||||
state->nb = nb;
|
||||
state->nn = nn;
|
||||
state->lno = state->nb;
|
||||
if (state->nn == 0) {
|
||||
/* @@ -X,Y +N,0 @@ removed Y lines
|
||||
* that would have come *after* line N
|
||||
* in the result. Our lost buckets hang
|
||||
* to the line after the removed lines,
|
||||
*
|
||||
* Note that this is correct even when N == 0,
|
||||
* in which case the hunk removes the first
|
||||
* line in the file.
|
||||
*/
|
||||
state->lost_bucket = &state->sline[state->nb];
|
||||
if (!state->nb)
|
||||
state->nb = 1;
|
||||
} else {
|
||||
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));
|
||||
state->sline[state->nb-1].p_lno[state->n] = state->ob;
|
||||
}
|
||||
|
||||
static void consume_line(void *state_, char *line, unsigned long len)
|
||||
{
|
||||
struct combine_diff_state *state = state_;
|
||||
if (5 < len && !memcmp("@@ -", line, 4)) {
|
||||
if (parse_hunk_header(line, len,
|
||||
&state->ob, &state->on,
|
||||
&state->nb, &state->nn))
|
||||
return;
|
||||
state->lno = state->nb;
|
||||
if (state->nn == 0) {
|
||||
/* @@ -X,Y +N,0 @@ removed Y lines
|
||||
* that would have come *after* line N
|
||||
* in the result. Our lost buckets hang
|
||||
* to the line after the removed lines,
|
||||
*
|
||||
* Note that this is correct even when N == 0,
|
||||
* in which case the hunk removes the first
|
||||
* line in the file.
|
||||
*/
|
||||
state->lost_bucket = &state->sline[state->nb];
|
||||
if (!state->nb)
|
||||
state->nb = 1;
|
||||
} else {
|
||||
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));
|
||||
state->sline[state->nb-1].p_lno[state->n] = state->ob;
|
||||
return;
|
||||
}
|
||||
if (!state->lost_bucket)
|
||||
return; /* not in any hunk yet */
|
||||
switch (line[0]) {
|
||||
@ -419,8 +424,8 @@ static void combine_diff(const struct object_id *parent, unsigned int mode,
|
||||
state.num_parent = num_parent;
|
||||
state.n = n;
|
||||
|
||||
if (xdi_diff_outf(&parent_file, result_file, NULL, consume_line,
|
||||
&state, &xpp, &xecfg))
|
||||
if (xdi_diff_outf(&parent_file, result_file, consume_hunk,
|
||||
consume_line, &state, &xpp, &xecfg))
|
||||
die("unable to generate combined diff for %s",
|
||||
oid_to_hex(parent));
|
||||
free(parent_file.ptr);
|
||||
|
Loading…
Reference in New Issue
Block a user