Merge branch 'jk/xdiff-interface'
The interface into "xdiff" library used to discover the offset and size of a generated patch hunk by first formatting it into the textual hunk header "@@ -n,m +k,l @@" and then parsing the numbers out. A new interface has been introduced to allow callers a more direct access to them. * jk/xdiff-interface: xdiff-interface: drop parse_hunk_header() range-diff: use a hunk callback diff: convert --check to use a hunk callback combine-diff: use an xdiff hunk callback diff: use hunk callback for word-diff diff: discard hunk headers for patch-ids earlier diff: avoid generating unused hunk header lines xdiff-interface: provide a separate consume callback for hunks xdiff: provide a separate emit callback for hunks
This commit is contained in:
@@ -345,38 +345,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]) {
|
||||
@@ -421,8 +426,8 @@ static void combine_diff(struct repository *r,
|
||||
state.num_parent = num_parent;
|
||||
state.n = n;
|
||||
|
||||
if (xdi_diff_outf(&parent_file, result_file, 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);
|
||||
|
||||
Reference in New Issue
Block a user