зеркало из https://github.com/microsoft/git.git
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:
Родитель
7c61e25fbf
Коммит
0074c9110d
|
@ -344,14 +344,17 @@ struct combine_diff_state {
|
|||
struct sline *lost_bucket;
|
||||
};
|
||||
|
||||
static void consume_line(void *state_, char *line, unsigned long len)
|
||||
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_;
|
||||
if (5 < len && !memcmp("@@ -", line, 4)) {
|
||||
if (parse_hunk_header(line, len,
|
||||
&state->ob, &state->on,
|
||||
&state->nb, &state->nn))
|
||||
return;
|
||||
|
||||
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
|
||||
|
@ -371,11 +374,13 @@ static void consume_line(void *state_, char *line, unsigned long len)
|
|||
}
|
||||
if (!state->sline[state->nb-1].p_lno)
|
||||
state->sline[state->nb-1].p_lno =
|
||||
xcalloc(state->num_parent,
|
||||
sizeof(unsigned long));
|
||||
xcalloc(state->num_parent, sizeof(unsigned long));
|
||||
state->sline[state->nb-1].p_lno[state->n] = state->ob;
|
||||
return;
|
||||
}
|
||||
|
||||
static void 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 */
|
||||
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);
|
||||
|
|
Загрузка…
Ссылка в новой задаче