Blob


1 /* Diff output generators and invocation shims. */
2 /*
3 * Copyright (c) 2020 Neels Hofmeyr <neels@hofmeyr.de>
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
18 struct diff_input_info {
19 const char *left_path;
20 const char *right_path;
22 /* Set by caller of diff_output_* functions. */
23 int flags;
24 #define DIFF_INPUT_LEFT_NONEXISTENT 0x00000001
25 #define DIFF_INPUT_RIGHT_NONEXISTENT 0x00000002
26 };
28 struct diff_output_info {
29 /*
30 * Byte offset to each line in the generated output file.
31 * The total number of lines in the file is line_offsets.len - 1.
32 * The last offset in this array corresponds to end-of-file.
33 */
34 ARRAYLIST(off_t) line_offsets;
35 };
37 void diff_output_info_free(struct diff_output_info *output_info);
39 struct diff_chunk_context {
40 struct diff_range chunk;
41 struct diff_range left, right;
42 };
44 int diff_output_plain(struct diff_output_info **output_info, FILE *dest,
45 const struct diff_input_info *info,
46 const struct diff_result *result);
47 int diff_output_unidiff(struct diff_output_info **output_info,
48 FILE *dest, const struct diff_input_info *info,
49 const struct diff_result *result,
50 unsigned int context_lines);
51 int diff_output_edscript(struct diff_output_info **output_info,
52 FILE *dest, const struct diff_input_info *info,
53 const struct diff_result *result);
54 int diff_chunk_get_left_start(const struct diff_chunk *c,
55 const struct diff_result *r,
56 int context_lines);
57 int diff_chunk_get_left_end(const struct diff_chunk *c,
58 const struct diff_result *r,
59 int context_lines);
60 int diff_chunk_get_right_start(const struct diff_chunk *c,
61 const struct diff_result *r,
62 int context_lines);
63 int diff_chunk_get_right_end(const struct diff_chunk *c,
64 const struct diff_result *r,
65 int context_lines);
66 struct diff_chunk *diff_chunk_get(const struct diff_result *r, int chunk_idx);
67 int diff_chunk_get_left_count(struct diff_chunk *c);
68 int diff_chunk_get_right_count(struct diff_chunk *c);
69 void diff_chunk_context_get(struct diff_chunk_context *cc,
70 const struct diff_result *r,
71 int chunk_idx, int context_lines);
72 void diff_chunk_context_load_change(struct diff_chunk_context *cc,
73 int *nchunks_used,
74 struct diff_result *result,
75 int start_chunk_idx,
76 int context_lines);
78 struct diff_output_unidiff_state;
79 struct diff_output_unidiff_state *diff_output_unidiff_state_alloc(void);
80 void diff_output_unidiff_state_reset(struct diff_output_unidiff_state *state);
81 void diff_output_unidiff_state_free(struct diff_output_unidiff_state *state);
82 int diff_output_unidiff_chunk(struct diff_output_info **output_info, FILE *dest,
83 struct diff_output_unidiff_state *state,
84 const struct diff_input_info *info,
85 const struct diff_result *result,
86 const struct diff_chunk_context *cc);
87 int diff_output_chunk_left_version(struct diff_output_info **output_info,
88 FILE *dest,
89 const struct diff_input_info *info,
90 const struct diff_result *result,
91 const struct diff_chunk_context *cc);
92 int diff_output_chunk_right_version(struct diff_output_info **output_info,
93 FILE *dest,
94 const struct diff_input_info *info,
95 const struct diff_result *result,
96 const struct diff_chunk_context *cc);
98 const char *diff_output_get_label_left(const struct diff_input_info *info);
99 const char *diff_output_get_label_right(const struct diff_input_info *info);