Blame


1 fe621944 2020-11-10 stsp /* Common parts for printing diff output */
2 fe621944 2020-11-10 stsp /*
3 fe621944 2020-11-10 stsp * Copyright (c) 2020 Neels Hofmeyr <neels@hofmeyr.de>
4 fe621944 2020-11-10 stsp *
5 fe621944 2020-11-10 stsp * Permission to use, copy, modify, and distribute this software for any
6 fe621944 2020-11-10 stsp * purpose with or without fee is hereby granted, provided that the above
7 fe621944 2020-11-10 stsp * copyright notice and this permission notice appear in all copies.
8 fe621944 2020-11-10 stsp *
9 fe621944 2020-11-10 stsp * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 fe621944 2020-11-10 stsp * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 fe621944 2020-11-10 stsp * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 fe621944 2020-11-10 stsp * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 fe621944 2020-11-10 stsp * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 fe621944 2020-11-10 stsp * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 fe621944 2020-11-10 stsp * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 fe621944 2020-11-10 stsp */
17 fe621944 2020-11-10 stsp
18 fe621944 2020-11-10 stsp #include <ctype.h>
19 fe621944 2020-11-10 stsp #include <errno.h>
20 fe621944 2020-11-10 stsp #include <stdbool.h>
21 f3c44083 2020-11-14 naddy #include <stdint.h>
22 fe621944 2020-11-10 stsp #include <stdio.h>
23 fe621944 2020-11-10 stsp #include <stdlib.h>
24 fe621944 2020-11-10 stsp #include <string.h>
25 fe621944 2020-11-10 stsp #include <unistd.h>
26 fe621944 2020-11-10 stsp
27 fe621944 2020-11-10 stsp #include <arraylist.h>
28 fe621944 2020-11-10 stsp #include <diff_main.h>
29 fe621944 2020-11-10 stsp #include <diff_output.h>
30 fe621944 2020-11-10 stsp
31 fe621944 2020-11-10 stsp #include "diff_internal.h"
32 fe621944 2020-11-10 stsp
33 fe621944 2020-11-10 stsp static int
34 fe621944 2020-11-10 stsp get_atom_byte(int *ch, struct diff_atom *atom, off_t off)
35 fe621944 2020-11-10 stsp {
36 fe621944 2020-11-10 stsp off_t cur;
37 fe621944 2020-11-10 stsp
38 fe621944 2020-11-10 stsp if (atom->at != NULL) {
39 fe621944 2020-11-10 stsp *ch = atom->at[off];
40 fe621944 2020-11-10 stsp return 0;
41 fe621944 2020-11-10 stsp }
42 fe621944 2020-11-10 stsp
43 fe621944 2020-11-10 stsp cur = ftello(atom->root->f);
44 fe621944 2020-11-10 stsp if (cur == -1)
45 fe621944 2020-11-10 stsp return errno;
46 fe621944 2020-11-10 stsp
47 fe621944 2020-11-10 stsp if (cur != atom->pos + off &&
48 fe621944 2020-11-10 stsp fseeko(atom->root->f, atom->pos + off, SEEK_SET) == -1)
49 fe621944 2020-11-10 stsp return errno;
50 fe621944 2020-11-10 stsp
51 fe621944 2020-11-10 stsp *ch = fgetc(atom->root->f);
52 fe621944 2020-11-10 stsp if (*ch == EOF && ferror(atom->root->f))
53 fe621944 2020-11-10 stsp return errno;
54 fe621944 2020-11-10 stsp
55 fe621944 2020-11-10 stsp return 0;
56 fe621944 2020-11-10 stsp }
57 fe621944 2020-11-10 stsp
58 4f655d1b 2021-07-08 stsp #define DIFF_OUTPUT_BUF_SIZE 512
59 4f655d1b 2021-07-08 stsp
60 fe621944 2020-11-10 stsp int
61 fe621944 2020-11-10 stsp diff_output_lines(struct diff_output_info *outinfo, FILE *dest,
62 fe621944 2020-11-10 stsp const char *prefix, struct diff_atom *start_atom,
63 fe621944 2020-11-10 stsp unsigned int count)
64 fe621944 2020-11-10 stsp {
65 fe621944 2020-11-10 stsp struct diff_atom *atom;
66 fe621944 2020-11-10 stsp off_t outoff = 0, *offp;
67 b77ebd68 2022-08-04 mark uint8_t *typep;
68 fe621944 2020-11-10 stsp int rc;
69 fe621944 2020-11-10 stsp
70 fe621944 2020-11-10 stsp if (outinfo && outinfo->line_offsets.len > 0) {
71 fe621944 2020-11-10 stsp unsigned int idx = outinfo->line_offsets.len - 1;
72 fe621944 2020-11-10 stsp outoff = outinfo->line_offsets.head[idx];
73 fe621944 2020-11-10 stsp }
74 fe621944 2020-11-10 stsp
75 fe621944 2020-11-10 stsp foreach_diff_atom(atom, start_atom, count) {
76 fe621944 2020-11-10 stsp off_t outlen = 0;
77 4f655d1b 2021-07-08 stsp int i, ch, nbuf = 0;
78 fe621944 2020-11-10 stsp unsigned int len = atom->len;
79 4f655d1b 2021-07-08 stsp unsigned char buf[DIFF_OUTPUT_BUF_SIZE + 1 /* '\n' */];
80 4f655d1b 2021-07-08 stsp size_t n;
81 4f655d1b 2021-07-08 stsp
82 4f655d1b 2021-07-08 stsp n = strlcpy(buf, prefix, sizeof(buf));
83 4f655d1b 2021-07-08 stsp if (n >= DIFF_OUTPUT_BUF_SIZE) /* leave room for '\n' */
84 4f655d1b 2021-07-08 stsp return ENOBUFS;
85 4f655d1b 2021-07-08 stsp nbuf += n;
86 4f655d1b 2021-07-08 stsp
87 fe621944 2020-11-10 stsp if (len) {
88 fe621944 2020-11-10 stsp rc = get_atom_byte(&ch, atom, len - 1);
89 fe621944 2020-11-10 stsp if (rc)
90 fe621944 2020-11-10 stsp return rc;
91 fe621944 2020-11-10 stsp if (ch == '\n')
92 fe621944 2020-11-10 stsp len--;
93 fe621944 2020-11-10 stsp }
94 fe621944 2020-11-10 stsp
95 fe621944 2020-11-10 stsp for (i = 0; i < len; i++) {
96 fe621944 2020-11-10 stsp rc = get_atom_byte(&ch, atom, i);
97 fe621944 2020-11-10 stsp if (rc)
98 fe621944 2020-11-10 stsp return rc;
99 4f655d1b 2021-07-08 stsp if (nbuf >= DIFF_OUTPUT_BUF_SIZE) {
100 4f655d1b 2021-07-08 stsp rc = fwrite(buf, 1, nbuf, dest);
101 4f655d1b 2021-07-08 stsp if (rc != nbuf)
102 4f655d1b 2021-07-08 stsp return errno;
103 4f655d1b 2021-07-08 stsp outlen += rc;
104 4f655d1b 2021-07-08 stsp nbuf = 0;
105 4f655d1b 2021-07-08 stsp }
106 4f655d1b 2021-07-08 stsp buf[nbuf++] = ch;
107 fe621944 2020-11-10 stsp }
108 4f655d1b 2021-07-08 stsp buf[nbuf++] = '\n';
109 4f655d1b 2021-07-08 stsp rc = fwrite(buf, 1, nbuf, dest);
110 4f655d1b 2021-07-08 stsp if (rc != nbuf)
111 fe621944 2020-11-10 stsp return errno;
112 fe621944 2020-11-10 stsp outlen += rc;
113 fe621944 2020-11-10 stsp if (outinfo) {
114 fe621944 2020-11-10 stsp ARRAYLIST_ADD(offp, outinfo->line_offsets);
115 fe621944 2020-11-10 stsp if (offp == NULL)
116 fe621944 2020-11-10 stsp return ENOMEM;
117 fe621944 2020-11-10 stsp outoff += outlen;
118 fe621944 2020-11-10 stsp *offp = outoff;
119 b77ebd68 2022-08-04 mark ARRAYLIST_ADD(typep, outinfo->line_types);
120 b77ebd68 2022-08-04 mark if (typep == NULL)
121 b77ebd68 2022-08-04 mark return ENOMEM;
122 b77ebd68 2022-08-04 mark *typep = *prefix == ' ' ? DIFF_LINE_CONTEXT :
123 b77ebd68 2022-08-04 mark *prefix == '-' ? DIFF_LINE_MINUS :
124 b77ebd68 2022-08-04 mark *prefix == '+' ? DIFF_LINE_PLUS : DIFF_LINE_NONE;
125 fe621944 2020-11-10 stsp }
126 fe621944 2020-11-10 stsp }
127 fe621944 2020-11-10 stsp
128 fe621944 2020-11-10 stsp return DIFF_RC_OK;
129 fe621944 2020-11-10 stsp }
130 fe621944 2020-11-10 stsp
131 fe621944 2020-11-10 stsp int
132 fe621944 2020-11-10 stsp diff_output_chunk_left_version(struct diff_output_info **output_info,
133 fe621944 2020-11-10 stsp FILE *dest,
134 fe621944 2020-11-10 stsp const struct diff_input_info *info,
135 fe621944 2020-11-10 stsp const struct diff_result *result,
136 fe621944 2020-11-10 stsp const struct diff_chunk_context *cc)
137 fe621944 2020-11-10 stsp {
138 fe621944 2020-11-10 stsp int rc, c_idx;
139 fe621944 2020-11-10 stsp struct diff_output_info *outinfo = NULL;
140 fe621944 2020-11-10 stsp
141 fe621944 2020-11-10 stsp if (diff_range_empty(&cc->left))
142 fe621944 2020-11-10 stsp return DIFF_RC_OK;
143 fe621944 2020-11-10 stsp
144 fe621944 2020-11-10 stsp if (output_info) {
145 fe621944 2020-11-10 stsp *output_info = diff_output_info_alloc();
146 fe621944 2020-11-10 stsp if (*output_info == NULL)
147 fe621944 2020-11-10 stsp return ENOMEM;
148 fe621944 2020-11-10 stsp outinfo = *output_info;
149 fe621944 2020-11-10 stsp }
150 fe621944 2020-11-10 stsp
151 fe621944 2020-11-10 stsp /* Write out all chunks on the left side. */
152 fe621944 2020-11-10 stsp for (c_idx = cc->chunk.start; c_idx < cc->chunk.end; c_idx++) {
153 fe621944 2020-11-10 stsp const struct diff_chunk *c = &result->chunks.head[c_idx];
154 fe621944 2020-11-10 stsp
155 fe621944 2020-11-10 stsp if (c->left_count) {
156 fe621944 2020-11-10 stsp rc = diff_output_lines(outinfo, dest, "",
157 fe621944 2020-11-10 stsp c->left_start, c->left_count);
158 fe621944 2020-11-10 stsp if (rc)
159 fe621944 2020-11-10 stsp return rc;
160 fe621944 2020-11-10 stsp }
161 fe621944 2020-11-10 stsp }
162 fe621944 2020-11-10 stsp
163 fe621944 2020-11-10 stsp return DIFF_RC_OK;
164 fe621944 2020-11-10 stsp }
165 fe621944 2020-11-10 stsp
166 fe621944 2020-11-10 stsp int
167 fe621944 2020-11-10 stsp diff_output_chunk_right_version(struct diff_output_info **output_info,
168 fe621944 2020-11-10 stsp FILE *dest,
169 fe621944 2020-11-10 stsp const struct diff_input_info *info,
170 fe621944 2020-11-10 stsp const struct diff_result *result,
171 fe621944 2020-11-10 stsp const struct diff_chunk_context *cc)
172 fe621944 2020-11-10 stsp {
173 fe621944 2020-11-10 stsp int rc, c_idx;
174 fe621944 2020-11-10 stsp struct diff_output_info *outinfo = NULL;
175 fe621944 2020-11-10 stsp
176 fe621944 2020-11-10 stsp if (diff_range_empty(&cc->right))
177 fe621944 2020-11-10 stsp return DIFF_RC_OK;
178 fe621944 2020-11-10 stsp
179 fe621944 2020-11-10 stsp if (output_info) {
180 fe621944 2020-11-10 stsp *output_info = diff_output_info_alloc();
181 fe621944 2020-11-10 stsp if (*output_info == NULL)
182 fe621944 2020-11-10 stsp return ENOMEM;
183 fe621944 2020-11-10 stsp outinfo = *output_info;
184 fe621944 2020-11-10 stsp }
185 fe621944 2020-11-10 stsp
186 fe621944 2020-11-10 stsp /* Write out all chunks on the right side. */
187 fe621944 2020-11-10 stsp for (c_idx = cc->chunk.start; c_idx < cc->chunk.end; c_idx++) {
188 fe621944 2020-11-10 stsp const struct diff_chunk *c = &result->chunks.head[c_idx];
189 fe621944 2020-11-10 stsp
190 fe621944 2020-11-10 stsp if (c->right_count) {
191 fe621944 2020-11-10 stsp rc = diff_output_lines(outinfo, dest, "", c->right_start,
192 fe621944 2020-11-10 stsp c->right_count);
193 fe621944 2020-11-10 stsp if (rc)
194 fe621944 2020-11-10 stsp return rc;
195 fe621944 2020-11-10 stsp }
196 fe621944 2020-11-10 stsp }
197 fe621944 2020-11-10 stsp
198 fe621944 2020-11-10 stsp return DIFF_RC_OK;
199 fe621944 2020-11-10 stsp }
200 fe621944 2020-11-10 stsp
201 fe621944 2020-11-10 stsp int
202 fe621944 2020-11-10 stsp diff_output_trailing_newline_msg(struct diff_output_info *outinfo, FILE *dest,
203 fe621944 2020-11-10 stsp const struct diff_chunk *c)
204 fe621944 2020-11-10 stsp {
205 fe621944 2020-11-10 stsp enum diff_chunk_type chunk_type = diff_chunk_type(c);
206 fe621944 2020-11-10 stsp struct diff_atom *atom, *start_atom;
207 fe621944 2020-11-10 stsp unsigned int atom_count;
208 fe621944 2020-11-10 stsp int rc, ch;
209 fe621944 2020-11-10 stsp off_t outoff = 0, *offp;
210 b77ebd68 2022-08-04 mark uint8_t *typep;
211 fe621944 2020-11-10 stsp
212 b77ebd68 2022-08-04 mark
213 fe621944 2020-11-10 stsp if (chunk_type == CHUNK_MINUS || chunk_type == CHUNK_SAME) {
214 fe621944 2020-11-10 stsp start_atom = c->left_start;
215 fe621944 2020-11-10 stsp atom_count = c->left_count;
216 fe621944 2020-11-10 stsp } else if (chunk_type == CHUNK_PLUS) {
217 fe621944 2020-11-10 stsp start_atom = c->right_start;
218 fe621944 2020-11-10 stsp atom_count = c->right_count;
219 fe621944 2020-11-10 stsp } else
220 fe621944 2020-11-10 stsp return EINVAL;
221 fe621944 2020-11-10 stsp
222 fe621944 2020-11-10 stsp /* Locate the last atom. */
223 fe621944 2020-11-10 stsp if (atom_count == 0)
224 fe621944 2020-11-10 stsp return EINVAL;
225 fe621944 2020-11-10 stsp atom = &start_atom[atom_count - 1];
226 fe621944 2020-11-10 stsp
227 fe621944 2020-11-10 stsp rc = get_atom_byte(&ch, atom, atom->len - 1);
228 fe621944 2020-11-10 stsp if (rc != DIFF_RC_OK)
229 fe621944 2020-11-10 stsp return rc;
230 fe621944 2020-11-10 stsp
231 fe621944 2020-11-10 stsp if (ch != '\n') {
232 fe621944 2020-11-10 stsp if (outinfo && outinfo->line_offsets.len > 0) {
233 fe621944 2020-11-10 stsp unsigned int idx = outinfo->line_offsets.len - 1;
234 fe621944 2020-11-10 stsp outoff = outinfo->line_offsets.head[idx];
235 fe621944 2020-11-10 stsp }
236 fe621944 2020-11-10 stsp rc = fprintf(dest, "\\ No newline at end of file\n");
237 fe621944 2020-11-10 stsp if (rc < 0)
238 fe621944 2020-11-10 stsp return errno;
239 fe621944 2020-11-10 stsp if (outinfo) {
240 fe621944 2020-11-10 stsp ARRAYLIST_ADD(offp, outinfo->line_offsets);
241 fe621944 2020-11-10 stsp if (offp == NULL)
242 fe621944 2020-11-10 stsp return ENOMEM;
243 fe621944 2020-11-10 stsp outoff += rc;
244 fe621944 2020-11-10 stsp *offp = outoff;
245 b77ebd68 2022-08-04 mark ARRAYLIST_ADD(typep, outinfo->line_types);
246 b77ebd68 2022-08-04 mark if (typep == NULL)
247 b77ebd68 2022-08-04 mark return ENOMEM;
248 b77ebd68 2022-08-04 mark *typep = DIFF_LINE_NONE;
249 fe621944 2020-11-10 stsp }
250 fe621944 2020-11-10 stsp }
251 fe621944 2020-11-10 stsp
252 fe621944 2020-11-10 stsp return DIFF_RC_OK;
253 fe621944 2020-11-10 stsp }
254 fe621944 2020-11-10 stsp
255 fe621944 2020-11-10 stsp static bool
256 f3b2b552 2020-12-10 stsp is_function_prototype(unsigned char ch)
257 fe621944 2020-11-10 stsp {
258 cee4532d 2022-11-17 op return (isalpha((unsigned char)ch) || ch == '_' || ch == '$');
259 fe621944 2020-11-10 stsp }
260 fe621944 2020-11-10 stsp
261 fe621944 2020-11-10 stsp #define begins_with(s, pre) (strncmp(s, pre, sizeof(pre)-1) == 0)
262 fe621944 2020-11-10 stsp
263 fe621944 2020-11-10 stsp int
264 f3b2b552 2020-12-10 stsp diff_output_match_function_prototype(char *prototype, size_t prototype_size,
265 f3b2b552 2020-12-10 stsp int *last_prototype_idx, const struct diff_result *result,
266 579042a9 2022-09-23 stsp const struct diff_chunk_context *cc, unsigned int ncontext)
267 fe621944 2020-11-10 stsp {
268 fe621944 2020-11-10 stsp struct diff_atom *start_atom, *atom;
269 fe621944 2020-11-10 stsp const struct diff_data *data;
270 f3b2b552 2020-12-10 stsp unsigned char buf[DIFF_FUNCTION_CONTEXT_SIZE];
271 58e31a80 2022-06-27 op const char *state = NULL;
272 579042a9 2022-09-23 stsp int rc, i, ch, idx;
273 579042a9 2022-09-23 stsp
274 579042a9 2022-09-23 stsp idx = MIN(cc->left.start + (ncontext ? ncontext : 0), cc->left.end - 1);
275 fe621944 2020-11-10 stsp
276 fe621944 2020-11-10 stsp if (result->left->atoms.len > 0 && cc->left.start > 0) {
277 fe621944 2020-11-10 stsp data = result->left;
278 579042a9 2022-09-23 stsp start_atom = &data->atoms.head[idx];
279 fe621944 2020-11-10 stsp } else
280 fe621944 2020-11-10 stsp return DIFF_RC_OK;
281 fe621944 2020-11-10 stsp
282 fe621944 2020-11-10 stsp diff_data_foreach_atom_backwards_from(start_atom, atom, data) {
283 f3b2b552 2020-12-10 stsp int atom_idx = diff_atom_root_idx(data, atom);
284 f3b2b552 2020-12-10 stsp if (atom_idx < *last_prototype_idx)
285 f3b2b552 2020-12-10 stsp break;
286 f3b2b552 2020-12-10 stsp rc = get_atom_byte(&ch, atom, 0);
287 f3b2b552 2020-12-10 stsp if (rc)
288 f3b2b552 2020-12-10 stsp return rc;
289 f3b2b552 2020-12-10 stsp buf[0] = (unsigned char)ch;
290 f3b2b552 2020-12-10 stsp if (!is_function_prototype(buf[0]))
291 f3b2b552 2020-12-10 stsp continue;
292 f3b2b552 2020-12-10 stsp for (i = 1; i < atom->len && i < sizeof(buf) - 1; i++) {
293 fe621944 2020-11-10 stsp rc = get_atom_byte(&ch, atom, i);
294 fe621944 2020-11-10 stsp if (rc)
295 fe621944 2020-11-10 stsp return rc;
296 fe621944 2020-11-10 stsp if (ch == '\n')
297 fe621944 2020-11-10 stsp break;
298 f3b2b552 2020-12-10 stsp buf[i] = (unsigned char)ch;
299 fe621944 2020-11-10 stsp }
300 fe621944 2020-11-10 stsp buf[i] = '\0';
301 f3b2b552 2020-12-10 stsp if (begins_with(buf, "private:")) {
302 f3b2b552 2020-12-10 stsp if (!state)
303 f3b2b552 2020-12-10 stsp state = " (private)";
304 f3b2b552 2020-12-10 stsp } else if (begins_with(buf, "protected:")) {
305 f3b2b552 2020-12-10 stsp if (!state)
306 f3b2b552 2020-12-10 stsp state = " (protected)";
307 f3b2b552 2020-12-10 stsp } else if (begins_with(buf, "public:")) {
308 f3b2b552 2020-12-10 stsp if (!state)
309 f3b2b552 2020-12-10 stsp state = " (public)";
310 f3b2b552 2020-12-10 stsp } else {
311 f3b2b552 2020-12-10 stsp if (state) /* don't care about truncation */
312 f3b2b552 2020-12-10 stsp strlcat(buf, state, sizeof(buf));
313 f3b2b552 2020-12-10 stsp strlcpy(prototype, buf, prototype_size);
314 f3b2b552 2020-12-10 stsp break;
315 fe621944 2020-11-10 stsp }
316 fe621944 2020-11-10 stsp }
317 fe621944 2020-11-10 stsp
318 f3b2b552 2020-12-10 stsp *last_prototype_idx = diff_atom_root_idx(data, start_atom);
319 fe621944 2020-11-10 stsp return DIFF_RC_OK;
320 fe621944 2020-11-10 stsp }
321 fe621944 2020-11-10 stsp
322 fe621944 2020-11-10 stsp struct diff_output_info *
323 fe621944 2020-11-10 stsp diff_output_info_alloc(void)
324 fe621944 2020-11-10 stsp {
325 fe621944 2020-11-10 stsp struct diff_output_info *output_info;
326 fe621944 2020-11-10 stsp off_t *offp;
327 b77ebd68 2022-08-04 mark uint8_t *typep;
328 fe621944 2020-11-10 stsp
329 fe621944 2020-11-10 stsp output_info = malloc(sizeof(*output_info));
330 fe621944 2020-11-10 stsp if (output_info != NULL) {
331 fe621944 2020-11-10 stsp ARRAYLIST_INIT(output_info->line_offsets, 128);
332 fe621944 2020-11-10 stsp ARRAYLIST_ADD(offp, output_info->line_offsets);
333 fe621944 2020-11-10 stsp if (offp == NULL) {
334 fe621944 2020-11-10 stsp diff_output_info_free(output_info);
335 fe621944 2020-11-10 stsp return NULL;
336 fe621944 2020-11-10 stsp }
337 fe621944 2020-11-10 stsp *offp = 0;
338 b77ebd68 2022-08-04 mark ARRAYLIST_INIT(output_info->line_types, 128);
339 b77ebd68 2022-08-04 mark ARRAYLIST_ADD(typep, output_info->line_types);
340 b77ebd68 2022-08-04 mark if (typep == NULL) {
341 b77ebd68 2022-08-04 mark diff_output_info_free(output_info);
342 b77ebd68 2022-08-04 mark return NULL;
343 b77ebd68 2022-08-04 mark }
344 b77ebd68 2022-08-04 mark *typep = DIFF_LINE_NONE;
345 fe621944 2020-11-10 stsp }
346 fe621944 2020-11-10 stsp return output_info;
347 fe621944 2020-11-10 stsp }
348 fe621944 2020-11-10 stsp
349 fe621944 2020-11-10 stsp void
350 fe621944 2020-11-10 stsp diff_output_info_free(struct diff_output_info *output_info)
351 fe621944 2020-11-10 stsp {
352 fe621944 2020-11-10 stsp ARRAYLIST_FREE(output_info->line_offsets);
353 b77ebd68 2022-08-04 mark ARRAYLIST_FREE(output_info->line_types);
354 fe621944 2020-11-10 stsp free(output_info);
355 c4cd9c5b 2020-11-21 stsp }
356 c4cd9c5b 2020-11-21 stsp
357 c4cd9c5b 2020-11-21 stsp const char *
358 c4cd9c5b 2020-11-21 stsp diff_output_get_label_left(const struct diff_input_info *info)
359 c4cd9c5b 2020-11-21 stsp {
360 c4cd9c5b 2020-11-21 stsp if (info->flags & DIFF_INPUT_LEFT_NONEXISTENT)
361 c4cd9c5b 2020-11-21 stsp return "/dev/null";
362 c4cd9c5b 2020-11-21 stsp
363 116d19d9 2022-09-02 mark return info->left_path ? info->left_path : "a";
364 c4cd9c5b 2020-11-21 stsp }
365 c4cd9c5b 2020-11-21 stsp
366 c4cd9c5b 2020-11-21 stsp const char *
367 c4cd9c5b 2020-11-21 stsp diff_output_get_label_right(const struct diff_input_info *info)
368 c4cd9c5b 2020-11-21 stsp {
369 c4cd9c5b 2020-11-21 stsp if (info->flags & DIFF_INPUT_RIGHT_NONEXISTENT)
370 c4cd9c5b 2020-11-21 stsp return "/dev/null";
371 c4cd9c5b 2020-11-21 stsp
372 116d19d9 2022-09-02 mark return info->right_path ? info->right_path : "b";
373 fe621944 2020-11-10 stsp }