Blame


1 1dfba055 2020-10-07 stsp /* Diff output generators and invocation shims. */
2 1dfba055 2020-10-07 stsp /*
3 1dfba055 2020-10-07 stsp * Copyright (c) 2020 Neels Hofmeyr <neels@hofmeyr.de>
4 1dfba055 2020-10-07 stsp *
5 1dfba055 2020-10-07 stsp * Permission to use, copy, modify, and distribute this software for any
6 1dfba055 2020-10-07 stsp * purpose with or without fee is hereby granted, provided that the above
7 1dfba055 2020-10-07 stsp * copyright notice and this permission notice appear in all copies.
8 1dfba055 2020-10-07 stsp *
9 1dfba055 2020-10-07 stsp * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 1dfba055 2020-10-07 stsp * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 1dfba055 2020-10-07 stsp * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 1dfba055 2020-10-07 stsp * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 1dfba055 2020-10-07 stsp * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 1dfba055 2020-10-07 stsp * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 1dfba055 2020-10-07 stsp * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 1dfba055 2020-10-07 stsp */
17 1dfba055 2020-10-07 stsp
18 1dfba055 2020-10-07 stsp struct diff_input_info {
19 1dfba055 2020-10-07 stsp const char *left_path;
20 1dfba055 2020-10-07 stsp const char *right_path;
21 e4c510c1 2020-11-21 stsp
22 e4c510c1 2020-11-21 stsp /* Set by caller of diff_output_* functions. */
23 e4c510c1 2020-11-21 stsp int flags;
24 e4c510c1 2020-11-21 stsp #define DIFF_INPUT_LEFT_NONEXISTENT 0x00000001
25 e4c510c1 2020-11-21 stsp #define DIFF_INPUT_RIGHT_NONEXISTENT 0x00000002
26 1dfba055 2020-10-07 stsp };
27 1dfba055 2020-10-07 stsp
28 1dfba055 2020-10-07 stsp struct diff_output_info {
29 1dfba055 2020-10-07 stsp /*
30 1dfba055 2020-10-07 stsp * Byte offset to each line in the generated output file.
31 1dfba055 2020-10-07 stsp * The total number of lines in the file is line_offsets.len - 1.
32 1dfba055 2020-10-07 stsp * The last offset in this array corresponds to end-of-file.
33 1dfba055 2020-10-07 stsp */
34 1dfba055 2020-10-07 stsp ARRAYLIST(off_t) line_offsets;
35 9343b925 2022-08-04 mark /*
36 9343b925 2022-08-04 mark * Type (i.e., context, minus, plus) of each line generated by the diff.
37 9343b925 2022-08-04 mark * nb. 0x00 to 0x3b reserved for client-defined line types.
38 9343b925 2022-08-04 mark */
39 9343b925 2022-08-04 mark ARRAYLIST(uint8_t) line_types;
40 9343b925 2022-08-04 mark #define DIFF_LINE_HUNK 0x3c
41 9343b925 2022-08-04 mark #define DIFF_LINE_MINUS 0x3d
42 9343b925 2022-08-04 mark #define DIFF_LINE_PLUS 0x3e
43 9343b925 2022-08-04 mark #define DIFF_LINE_CONTEXT 0x3f
44 9343b925 2022-08-04 mark #define DIFF_LINE_NONE 0x40 /* binary or no EOF newline msg, etc. */
45 1dfba055 2020-10-07 stsp };
46 1dfba055 2020-10-07 stsp
47 1dfba055 2020-10-07 stsp void diff_output_info_free(struct diff_output_info *output_info);
48 1dfba055 2020-10-07 stsp
49 1dfba055 2020-10-07 stsp struct diff_chunk_context {
50 1dfba055 2020-10-07 stsp struct diff_range chunk;
51 1dfba055 2020-10-07 stsp struct diff_range left, right;
52 1dfba055 2020-10-07 stsp };
53 1dfba055 2020-10-07 stsp
54 1dfba055 2020-10-07 stsp int diff_output_plain(struct diff_output_info **output_info, FILE *dest,
55 1dfba055 2020-10-07 stsp const struct diff_input_info *info,
56 1edd9c2b 2022-09-23 stsp const struct diff_result *result,
57 1edd9c2b 2022-09-23 stsp int hunk_headers_only);
58 1dfba055 2020-10-07 stsp int diff_output_unidiff(struct diff_output_info **output_info,
59 1dfba055 2020-10-07 stsp FILE *dest, const struct diff_input_info *info,
60 1dfba055 2020-10-07 stsp const struct diff_result *result,
61 1dfba055 2020-10-07 stsp unsigned int context_lines);
62 b7ba71f0 2020-10-07 stsp int diff_output_edscript(struct diff_output_info **output_info,
63 b7ba71f0 2020-10-07 stsp FILE *dest, const struct diff_input_info *info,
64 b7ba71f0 2020-10-07 stsp const struct diff_result *result);
65 1dfba055 2020-10-07 stsp int diff_chunk_get_left_start(const struct diff_chunk *c,
66 1dfba055 2020-10-07 stsp const struct diff_result *r,
67 1dfba055 2020-10-07 stsp int context_lines);
68 1dfba055 2020-10-07 stsp int diff_chunk_get_left_end(const struct diff_chunk *c,
69 1dfba055 2020-10-07 stsp const struct diff_result *r,
70 1dfba055 2020-10-07 stsp int context_lines);
71 1dfba055 2020-10-07 stsp int diff_chunk_get_right_start(const struct diff_chunk *c,
72 1dfba055 2020-10-07 stsp const struct diff_result *r,
73 1dfba055 2020-10-07 stsp int context_lines);
74 1dfba055 2020-10-07 stsp int diff_chunk_get_right_end(const struct diff_chunk *c,
75 1dfba055 2020-10-07 stsp const struct diff_result *r,
76 1dfba055 2020-10-07 stsp int context_lines);
77 f26db7cd 2023-02-20 mark off_t diff_chunk_get_left_start_pos(const struct diff_chunk *c);
78 f26db7cd 2023-02-20 mark off_t diff_chunk_get_right_start_pos(const struct diff_chunk *c);
79 e8eedebc 2020-11-06 stsp struct diff_chunk *diff_chunk_get(const struct diff_result *r, int chunk_idx);
80 e8eedebc 2020-11-06 stsp int diff_chunk_get_left_count(struct diff_chunk *c);
81 e8eedebc 2020-11-06 stsp int diff_chunk_get_right_count(struct diff_chunk *c);
82 1dfba055 2020-10-07 stsp void diff_chunk_context_get(struct diff_chunk_context *cc,
83 1dfba055 2020-10-07 stsp const struct diff_result *r,
84 1dfba055 2020-10-07 stsp int chunk_idx, int context_lines);
85 7187fe97 2020-10-17 stsp void diff_chunk_context_load_change(struct diff_chunk_context *cc,
86 7187fe97 2020-10-17 stsp int *nchunks_used,
87 7187fe97 2020-10-17 stsp struct diff_result *result,
88 7187fe97 2020-10-17 stsp int start_chunk_idx,
89 7187fe97 2020-10-17 stsp int context_lines);
90 7187fe97 2020-10-17 stsp
91 1dfba055 2020-10-07 stsp struct diff_output_unidiff_state;
92 1dfba055 2020-10-07 stsp struct diff_output_unidiff_state *diff_output_unidiff_state_alloc(void);
93 1dfba055 2020-10-07 stsp void diff_output_unidiff_state_reset(struct diff_output_unidiff_state *state);
94 1dfba055 2020-10-07 stsp void diff_output_unidiff_state_free(struct diff_output_unidiff_state *state);
95 1dfba055 2020-10-07 stsp int diff_output_unidiff_chunk(struct diff_output_info **output_info, FILE *dest,
96 1dfba055 2020-10-07 stsp struct diff_output_unidiff_state *state,
97 1dfba055 2020-10-07 stsp const struct diff_input_info *info,
98 1dfba055 2020-10-07 stsp const struct diff_result *result,
99 1dfba055 2020-10-07 stsp const struct diff_chunk_context *cc);
100 1dfba055 2020-10-07 stsp int diff_output_chunk_left_version(struct diff_output_info **output_info,
101 1dfba055 2020-10-07 stsp FILE *dest,
102 1dfba055 2020-10-07 stsp const struct diff_input_info *info,
103 1dfba055 2020-10-07 stsp const struct diff_result *result,
104 1dfba055 2020-10-07 stsp const struct diff_chunk_context *cc);
105 1dfba055 2020-10-07 stsp int diff_output_chunk_right_version(struct diff_output_info **output_info,
106 1dfba055 2020-10-07 stsp FILE *dest,
107 1dfba055 2020-10-07 stsp const struct diff_input_info *info,
108 1dfba055 2020-10-07 stsp const struct diff_result *result,
109 1dfba055 2020-10-07 stsp const struct diff_chunk_context *cc);
110 e4c510c1 2020-11-21 stsp
111 e4c510c1 2020-11-21 stsp const char *diff_output_get_label_left(const struct diff_input_info *info);
112 e4c510c1 2020-11-21 stsp const char *diff_output_get_label_right(const struct diff_input_info *info);