commit - 9230203d371721cf5bde99f526fe40740aea3b21
commit + 8993f42562696079866fc2dec7191877b6cc1f18
blob - 396f264aae799c02ce62d47c6762b7dc5bd05331
blob + be72763dedcb12e2baabb6fda64e06d2fcf5f598
--- lib/diff_internal.h
+++ lib/diff_internal.h
int diff_output_match_function_prototype(char *prototype, size_t prototype_size,
int *last_prototype_idx,
const struct diff_result *result,
- const struct diff_chunk_context *cc);
+ const struct diff_chunk_context *cc,
+ unsigned int ncontext);
struct diff_output_info *diff_output_info_alloc(void);
blob - 3047221aa5a15e4fc2a5dea8267e97864da21264
blob + bc44a51ea36b8a3a7cd5581e6787fcdda23168c6
--- lib/diff_output.c
+++ lib/diff_output.c
int
diff_output_match_function_prototype(char *prototype, size_t prototype_size,
int *last_prototype_idx, const struct diff_result *result,
- const struct diff_chunk_context *cc)
+ const struct diff_chunk_context *cc, unsigned int ncontext)
{
struct diff_atom *start_atom, *atom;
const struct diff_data *data;
unsigned char buf[DIFF_FUNCTION_CONTEXT_SIZE];
const char *state = NULL;
- int rc, i, ch;
+ int rc, i, ch, idx;
+
+ idx = MIN(cc->left.start + (ncontext ? ncontext : 0), cc->left.end - 1);
if (result->left->atoms.len > 0 && cc->left.start > 0) {
data = result->left;
- start_atom = &data->atoms.head[cc->left.start - 1];
+ start_atom = &data->atoms.head[idx];
} else
return DIFF_RC_OK;
blob - 18bff74063081228c1c525cce2b35ad26a527bf8
blob + 74b22eb8207ab2c5f154a22229051900a3d7b1ce
--- lib/diff_output_unidiff.c
+++ lib/diff_output_unidiff.c
const struct diff_input_info *info,
const struct diff_result *result,
bool print_header, bool show_function_prototypes,
- const struct diff_chunk_context *cc)
+ const struct diff_chunk_context *cc, unsigned int ncontext)
{
int rc, left_start, left_len, right_start, right_len;
off_t outoff = 0, *offp;
if (show_function_prototypes) {
rc = diff_output_match_function_prototype(state->prototype,
sizeof(state->prototype), &state->last_prototype_idx,
- result, cc);
+ result, cc, ncontext);
if (rc)
return rc;
}
}
return output_unidiff_chunk(outinfo, dest, state, info,
- result, false, show_function_prototypes, cc);
+ result, false, show_function_prototypes, cc, 0);
}
int
" print left %d-%d right %d-%d\n",
cc.left.start, cc.left.end, cc.right.start, cc.right.end);
output_unidiff_chunk(outinfo, dest, state, info, result,
- true, show_function_prototypes, &cc);
+ true, show_function_prototypes, &cc, context_lines);
cc = next;
debug("new unprinted chunk is left %d-%d right %d-%d\n",
cc.left.start, cc.left.end, cc.right.start, cc.right.end);
if (!diff_chunk_context_empty(&cc))
output_unidiff_chunk(outinfo, dest, state, info, result,
- true, show_function_prototypes, &cc);
+ true, show_function_prototypes, &cc, context_lines);
diff_output_unidiff_state_free(state);
return DIFF_RC_OK;
}