commit db941c245fd5f7b8e8ca2f9b6ebaf0c3dcecda48 from: Stefan Sperling date: Fri Oct 16 22:52:38 2020 UTC put functions required for using diff_output_unidiff_chunk() into public API They will be needed to implement 'got stage -p' and 'got revert -p', etc. Chunks stored in diff_result still need post-processing in order to be displayed as expected by diff_output_unidiff_chunk(). Exposing these functions allows API consumers to implement the same chunk merging loop as used internally by output_unidiff() and output_edscript(). (Perhaps, ideally, the public diff API would provide pre-merged chunks at some point in the future? Then this commit could probably be reverted.) Change return values from bool to int to avoid making stdbool.h a requirement for the public diff API. commit - cbf93b702bb81f143354b53125c64579a5040fcc commit + db941c245fd5f7b8e8ca2f9b6ebaf0c3dcecda48 blob - eb5ea9058a20bee4cbe0ab59e51b057ac8067878 blob + 788ee7f70a4767c36639c50287ba611f2f917dda --- include/diff_output.h +++ include/diff_output.h @@ -61,6 +61,12 @@ int diff_chunk_get_right_end(const struct diff_chunk * void diff_chunk_context_get(struct diff_chunk_context *cc, const struct diff_result *r, int chunk_idx, int context_lines); +int diff_chunk_context_empty(const struct diff_chunk_context *cc); +int diff_chunk_contexts_touch(const struct diff_chunk_context *cc, + const struct diff_chunk_context *other); +void diff_chunk_contexts_merge(struct diff_chunk_context *cc, + const struct diff_chunk_context *other); + struct diff_output_unidiff_state; struct diff_output_unidiff_state *diff_output_unidiff_state_alloc(void); void diff_output_unidiff_state_reset(struct diff_output_unidiff_state *state); blob - f48c869ab05318ba318a42e11631e120cedb7cb6 blob + 1895fddf12374a72d9b814e673fe12a6e3737678 --- lib/diff_internal.h +++ lib/diff_internal.h @@ -178,19 +178,6 @@ diff_chunk_type(const struct diff_chunk *chunk) return CHUNK_SAME; } -struct diff_chunk_context; - -bool -diff_chunk_context_empty(const struct diff_chunk_context *cc); - -bool -diff_chunk_contexts_touch(const struct diff_chunk_context *cc, - const struct diff_chunk_context *other); - -void -diff_chunk_contexts_merge(struct diff_chunk_context *cc, - const struct diff_chunk_context *other); - struct diff_state { /* The final result passed to the original diff caller. */ struct diff_result *result; blob - 1d7534ed300500cb5a0da2b4dbcad1d6b448a7cf blob + c4259e18e965b715f404bfcfb23821be55b30468 --- lib/diff_output_unidiff.c +++ lib/diff_output_unidiff.c @@ -28,7 +28,7 @@ #include "diff_internal.h" #include "diff_debug.h" -bool +int diff_chunk_context_empty(const struct diff_chunk_context *cc) { return diff_range_empty(&cc->chunk); @@ -94,7 +94,7 @@ diff_chunk_context_get(struct diff_chunk_context *cc, }; } -bool +int diff_chunk_contexts_touch(const struct diff_chunk_context *cc, const struct diff_chunk_context *other) {