Blame


1 574ed2c3 2017-11-29 stsp /*
2 fe621944 2020-11-10 stsp * Copyright (c) 2020 Neels Hofmeyr <neels@hofmeyr.de>
3 fe621944 2020-11-10 stsp * Copyright (c) 2020 Stefan Sperling <stsp@openbsd.org>
4 574ed2c3 2017-11-29 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 574ed2c3 2017-11-29 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 574ed2c3 2017-11-29 stsp */
17 574ed2c3 2017-11-29 stsp
18 fe621944 2020-11-10 stsp #include <sys/mman.h>
19 574ed2c3 2017-11-29 stsp #include <sys/stat.h>
20 7d283eee 2017-11-29 stsp #include <sys/queue.h>
21 574ed2c3 2017-11-29 stsp
22 574ed2c3 2017-11-29 stsp #include <errno.h>
23 d7b5a0e8 2022-04-20 stsp #include <sha1.h>
24 574ed2c3 2017-11-29 stsp #include <stdio.h>
25 574ed2c3 2017-11-29 stsp #include <stdlib.h>
26 574ed2c3 2017-11-29 stsp #include <string.h>
27 574ed2c3 2017-11-29 stsp
28 7d283eee 2017-11-29 stsp #include "got_object.h"
29 fe621944 2020-11-10 stsp #include "got_opentemp.h"
30 fe621944 2020-11-10 stsp #include "got_error.h"
31 4b752015 2022-06-30 stsp #include "got_diff.h"
32 7d283eee 2017-11-29 stsp
33 718b3ab0 2018-03-17 stsp #include "got_lib_diff.h"
34 574ed2c3 2017-11-29 stsp
35 fe621944 2020-11-10 stsp const struct diff_algo_config myers_then_patience;
36 fe621944 2020-11-10 stsp const struct diff_algo_config myers_then_myers_divide;
37 fe621944 2020-11-10 stsp const struct diff_algo_config patience;
38 fe621944 2020-11-10 stsp const struct diff_algo_config myers_divide;
39 574ed2c3 2017-11-29 stsp
40 7a52a8bc 2022-11-03 stsp const struct diff_algo_config myers_then_patience = {
41 fe621944 2020-11-10 stsp .impl = diff_algo_myers,
42 fe621944 2020-11-10 stsp .permitted_state_size = 1024 * 1024 * sizeof(int),
43 fe621944 2020-11-10 stsp .fallback_algo = &patience,
44 fe621944 2020-11-10 stsp };
45 574ed2c3 2017-11-29 stsp
46 7a52a8bc 2022-11-03 stsp const struct diff_algo_config myers_then_myers_divide = {
47 fe621944 2020-11-10 stsp .impl = diff_algo_myers,
48 fe621944 2020-11-10 stsp .permitted_state_size = 1024 * 1024 * sizeof(int),
49 fe621944 2020-11-10 stsp .fallback_algo = &myers_divide,
50 fe621944 2020-11-10 stsp };
51 574ed2c3 2017-11-29 stsp
52 7a52a8bc 2022-11-03 stsp const struct diff_algo_config patience = {
53 fe621944 2020-11-10 stsp .impl = diff_algo_patience,
54 fe621944 2020-11-10 stsp /* After subdivision, do Patience again: */
55 fe621944 2020-11-10 stsp .inner_algo = &patience,
56 fe621944 2020-11-10 stsp /* If subdivision failed, do Myers Divide et Impera: */
57 fe621944 2020-11-10 stsp .fallback_algo = &myers_then_myers_divide,
58 574ed2c3 2017-11-29 stsp };
59 574ed2c3 2017-11-29 stsp
60 7a52a8bc 2022-11-03 stsp const struct diff_algo_config myers_divide = {
61 fe621944 2020-11-10 stsp .impl = diff_algo_myers_divide,
62 fe621944 2020-11-10 stsp /* When division succeeded, start from the top: */
63 fe621944 2020-11-10 stsp .inner_algo = &myers_then_myers_divide,
64 fe621944 2020-11-10 stsp /* (fallback_algo = NULL implies diff_algo_none). */
65 8020fd50 2017-11-29 stsp };
66 574ed2c3 2017-11-29 stsp
67 fe621944 2020-11-10 stsp /* If the state for a forward-Myers is small enough, use Myers, otherwise first
68 fe621944 2020-11-10 stsp * do a Myers-divide. */
69 fe621944 2020-11-10 stsp const struct diff_config diff_config_myers_then_myers_divide = {
70 fe621944 2020-11-10 stsp .atomize_func = diff_atomize_text_by_line,
71 fe621944 2020-11-10 stsp .algo = &myers_then_myers_divide,
72 fe621944 2020-11-10 stsp };
73 574ed2c3 2017-11-29 stsp
74 fe621944 2020-11-10 stsp /* If the state for a forward-Myers is small enough, use Myers, otherwise first
75 fe621944 2020-11-10 stsp * do a Patience. */
76 fe621944 2020-11-10 stsp const struct diff_config diff_config_myers_then_patience = {
77 fe621944 2020-11-10 stsp .atomize_func = diff_atomize_text_by_line,
78 fe621944 2020-11-10 stsp .algo = &myers_then_patience,
79 574ed2c3 2017-11-29 stsp };
80 574ed2c3 2017-11-29 stsp
81 fe621944 2020-11-10 stsp /* Directly force Patience as a first divider of the source file. */
82 fe621944 2020-11-10 stsp const struct diff_config diff_config_patience = {
83 fe621944 2020-11-10 stsp .atomize_func = diff_atomize_text_by_line,
84 fe621944 2020-11-10 stsp .algo = &patience,
85 574ed2c3 2017-11-29 stsp };
86 574ed2c3 2017-11-29 stsp
87 fe621944 2020-11-10 stsp /* Directly force Patience as a first divider of the source file. */
88 fe621944 2020-11-10 stsp const struct diff_config diff_config_no_algo = {
89 fe621944 2020-11-10 stsp .atomize_func = diff_atomize_text_by_line,
90 fe621944 2020-11-10 stsp };
91 fe621944 2020-11-10 stsp
92 fe621944 2020-11-10 stsp const struct got_error *
93 49d4a017 2022-06-30 stsp got_diffreg_close(char *p1, size_t size1, char *p2, size_t size2)
94 cb74ff21 2017-11-30 stsp {
95 fe621944 2020-11-10 stsp const struct got_error *err = NULL;
96 cb74ff21 2017-11-30 stsp
97 fe621944 2020-11-10 stsp if (p1 && munmap(p1, size1) == -1 && err == NULL)
98 fe621944 2020-11-10 stsp err = got_error_from_errno("munmap");
99 fe621944 2020-11-10 stsp if (p2 && munmap(p2, size2) == -1 && err == NULL)
100 fe621944 2020-11-10 stsp err = got_error_from_errno("munmap");
101 fe621944 2020-11-10 stsp return err;
102 dc424a06 2019-08-07 stsp }
103 dc424a06 2019-08-07 stsp
104 cca5682e 2020-11-18 stsp const struct got_error *
105 cca5682e 2020-11-18 stsp got_diff_get_config(struct diff_config **cfg,
106 cca5682e 2020-11-18 stsp enum got_diff_algorithm algorithm,
107 cca5682e 2020-11-18 stsp diff_atomize_func_t atomize_func, void *atomize_func_data)
108 dc424a06 2019-08-07 stsp {
109 cca5682e 2020-11-18 stsp *cfg = calloc(1, sizeof(**cfg));
110 cca5682e 2020-11-18 stsp if (*cfg == NULL)
111 cca5682e 2020-11-18 stsp return got_error_from_errno("calloc");
112 cca5682e 2020-11-18 stsp
113 fe621944 2020-11-10 stsp switch (algorithm) {
114 fe621944 2020-11-10 stsp case GOT_DIFF_ALGORITHM_PATIENCE:
115 cca5682e 2020-11-18 stsp (*cfg)->algo = &patience;
116 cca5682e 2020-11-18 stsp break;
117 fe621944 2020-11-10 stsp case GOT_DIFF_ALGORITHM_MYERS:
118 cca5682e 2020-11-18 stsp (*cfg)->algo = &myers_then_myers_divide;
119 cca5682e 2020-11-18 stsp break;
120 cca5682e 2020-11-18 stsp default:
121 cca5682e 2020-11-18 stsp return got_error_msg(GOT_ERR_NOT_IMPL, "bad diff algorithm");
122 fe621944 2020-11-10 stsp }
123 cca5682e 2020-11-18 stsp
124 cca5682e 2020-11-18 stsp if (atomize_func) {
125 cca5682e 2020-11-18 stsp (*cfg)->atomize_func = atomize_func;
126 cca5682e 2020-11-18 stsp (*cfg)->atomize_func_data = atomize_func_data;
127 cca5682e 2020-11-18 stsp } else
128 cca5682e 2020-11-18 stsp (*cfg)->atomize_func = diff_atomize_text_by_line;
129 cca5682e 2020-11-18 stsp
130 cca5682e 2020-11-18 stsp (*cfg)->max_recursion_depth = 0; /* use default recursion depth */
131 cca5682e 2020-11-18 stsp
132 cca5682e 2020-11-18 stsp return NULL;
133 cb74ff21 2017-11-30 stsp }
134 cb74ff21 2017-11-30 stsp
135 7d283eee 2017-11-29 stsp const struct got_error *
136 72254787 2020-11-18 stsp got_diff_prepare_file(FILE *f, char **p, size_t *size,
137 fe621944 2020-11-10 stsp struct diff_data *diff_data, const struct diff_config *cfg,
138 64453f7e 2020-11-21 stsp int ignore_whitespace, int force_text_diff)
139 574ed2c3 2017-11-29 stsp {
140 7d283eee 2017-11-29 stsp const struct got_error *err = NULL;
141 fe621944 2020-11-10 stsp struct stat st;
142 fe621944 2020-11-10 stsp int diff_flags = 0, rc;
143 7d283eee 2017-11-29 stsp
144 fe621944 2020-11-10 stsp *size = 0;
145 fe621944 2020-11-10 stsp
146 fe621944 2020-11-10 stsp diff_flags |= DIFF_FLAG_SHOW_PROTOTYPES;
147 fe621944 2020-11-10 stsp if (ignore_whitespace)
148 fe621944 2020-11-10 stsp diff_flags |= DIFF_FLAG_IGNORE_WHITESPACE;
149 64453f7e 2020-11-21 stsp if (force_text_diff)
150 64453f7e 2020-11-21 stsp diff_flags |= DIFF_FLAG_FORCE_TEXT_DATA;
151 fe621944 2020-11-10 stsp
152 72254787 2020-11-18 stsp if (fstat(fileno(f), &st) == -1) {
153 72254787 2020-11-18 stsp err = got_error_from_errno("fstat");
154 72254787 2020-11-18 stsp goto done;
155 fe621944 2020-11-10 stsp }
156 72254787 2020-11-18 stsp #ifndef GOT_DIFF_NO_MMAP
157 72254787 2020-11-18 stsp *p = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE,
158 72254787 2020-11-18 stsp fileno(f), 0);
159 72254787 2020-11-18 stsp if (*p == MAP_FAILED)
160 72254787 2020-11-18 stsp #endif
161 72254787 2020-11-18 stsp *p = NULL; /* fall back on file I/O */
162 fe621944 2020-11-10 stsp
163 72254787 2020-11-18 stsp rc = diff_atomize_file(diff_data, cfg, f, *p, st.st_size, diff_flags);
164 fe621944 2020-11-10 stsp if (rc) {
165 fe621944 2020-11-10 stsp err = got_error_set_errno(rc, "diff_atomize_file");
166 fe621944 2020-11-10 stsp goto done;
167 fe621944 2020-11-10 stsp }
168 fe621944 2020-11-10 stsp done:
169 fe621944 2020-11-10 stsp if (err)
170 fe621944 2020-11-10 stsp diff_data_free(diff_data);
171 574ed2c3 2017-11-29 stsp else
172 fe621944 2020-11-10 stsp *size = st.st_size;
173 fe621944 2020-11-10 stsp return err;
174 fe621944 2020-11-10 stsp }
175 fe621944 2020-11-10 stsp
176 fe621944 2020-11-10 stsp const struct got_error *
177 fe621944 2020-11-10 stsp got_diffreg(struct got_diffreg_result **diffreg_result, FILE *f1, FILE *f2,
178 64453f7e 2020-11-21 stsp enum got_diff_algorithm algorithm, int ignore_whitespace,
179 64453f7e 2020-11-21 stsp int force_text_diff)
180 fe621944 2020-11-10 stsp {
181 fe621944 2020-11-10 stsp const struct got_error *err = NULL;
182 cca5682e 2020-11-18 stsp struct diff_config *cfg = NULL;
183 fe621944 2020-11-10 stsp char *p1 = NULL, *p2 = NULL;
184 fe621944 2020-11-10 stsp size_t size1, size2;
185 fe621944 2020-11-10 stsp struct diff_data d_left, d_right;
186 fe621944 2020-11-10 stsp struct diff_data *left, *right;
187 fe621944 2020-11-10 stsp struct diff_result *diff_result;
188 574ed2c3 2017-11-29 stsp
189 fe621944 2020-11-10 stsp if (diffreg_result) {
190 fe621944 2020-11-10 stsp *diffreg_result = calloc(1, sizeof(**diffreg_result));
191 fe621944 2020-11-10 stsp if (*diffreg_result == NULL)
192 fe621944 2020-11-10 stsp return got_error_from_errno("calloc");
193 fe621944 2020-11-10 stsp left = &(*diffreg_result)->left;
194 fe621944 2020-11-10 stsp right = &(*diffreg_result)->right;
195 fe621944 2020-11-10 stsp } else {
196 fe621944 2020-11-10 stsp memset(&d_left, 0, sizeof(d_left));
197 fe621944 2020-11-10 stsp memset(&d_right, 0, sizeof(d_right));
198 fe621944 2020-11-10 stsp left = &d_left;
199 fe621944 2020-11-10 stsp right = &d_right;
200 574ed2c3 2017-11-29 stsp }
201 72254787 2020-11-18 stsp
202 cca5682e 2020-11-18 stsp err = got_diff_get_config(&cfg, algorithm, NULL, NULL);
203 cca5682e 2020-11-18 stsp if (err)
204 fe621944 2020-11-10 stsp goto done;
205 574ed2c3 2017-11-29 stsp
206 72254787 2020-11-18 stsp err = got_diff_prepare_file(f1, &p1, &size1, left, cfg,
207 64453f7e 2020-11-21 stsp ignore_whitespace, force_text_diff);
208 fe621944 2020-11-10 stsp if (err)
209 fe621944 2020-11-10 stsp goto done;
210 574ed2c3 2017-11-29 stsp
211 72254787 2020-11-18 stsp err = got_diff_prepare_file(f2, &p2, &size2, right, cfg,
212 64453f7e 2020-11-21 stsp ignore_whitespace, force_text_diff);
213 fe621944 2020-11-10 stsp if (err)
214 fe621944 2020-11-10 stsp goto done;
215 574ed2c3 2017-11-29 stsp
216 fe621944 2020-11-10 stsp diff_result = diff_main(cfg, left, right);
217 fe621944 2020-11-10 stsp if (diff_result == NULL) {
218 fe621944 2020-11-10 stsp err = got_error_set_errno(ENOMEM, "malloc");
219 fe621944 2020-11-10 stsp goto done;
220 322260e1 2018-01-26 mpi }
221 fe621944 2020-11-10 stsp if (diff_result->rc != DIFF_RC_OK) {
222 fe621944 2020-11-10 stsp err = got_error_set_errno(diff_result->rc, "diff");
223 fe621944 2020-11-10 stsp goto done;
224 7d283eee 2017-11-29 stsp }
225 574ed2c3 2017-11-29 stsp
226 fe621944 2020-11-10 stsp if (diffreg_result) {
227 fe621944 2020-11-10 stsp (*diffreg_result)->result = diff_result;
228 fe621944 2020-11-10 stsp (*diffreg_result)->map1 = p1;
229 fe621944 2020-11-10 stsp (*diffreg_result)->size1 = size1;
230 fe621944 2020-11-10 stsp (*diffreg_result)->map2 = p2;
231 fe621944 2020-11-10 stsp (*diffreg_result)->size2 = size2;
232 7d283eee 2017-11-29 stsp }
233 fe621944 2020-11-10 stsp done:
234 cca5682e 2020-11-18 stsp free(cfg);
235 fe621944 2020-11-10 stsp if (diffreg_result == NULL) {
236 fe621944 2020-11-10 stsp diff_data_free(left);
237 fe621944 2020-11-10 stsp diff_data_free(right);
238 7d283eee 2017-11-29 stsp }
239 fe621944 2020-11-10 stsp if (err) {
240 49d4a017 2022-06-30 stsp got_diffreg_close(p1, size1, p2, size2);
241 fe621944 2020-11-10 stsp if (diffreg_result) {
242 fe621944 2020-11-10 stsp diff_data_free(left);
243 fe621944 2020-11-10 stsp diff_data_free(right);
244 fe621944 2020-11-10 stsp free(*diffreg_result);
245 fe621944 2020-11-10 stsp *diffreg_result = NULL;
246 fe621944 2020-11-10 stsp }
247 322260e1 2018-01-26 mpi }
248 5e91dae4 2022-08-30 stsp
249 fe621944 2020-11-10 stsp return err;
250 574ed2c3 2017-11-29 stsp }
251 574ed2c3 2017-11-29 stsp
252 fe621944 2020-11-10 stsp const struct got_error *
253 c7d5c43c 2022-08-04 mark got_diffreg_output(struct got_diff_line **lines, size_t *nlines,
254 1cb46f00 2020-11-21 stsp struct got_diffreg_result *diff_result, int f1_exists, int f2_exists,
255 fe621944 2020-11-10 stsp const char *path1, const char *path2,
256 fe621944 2020-11-10 stsp enum got_diff_output_format output_format, int context_lines, FILE *outfile)
257 574ed2c3 2017-11-29 stsp {
258 fe621944 2020-11-10 stsp struct diff_input_info info = {
259 fe621944 2020-11-10 stsp .left_path = path1,
260 fe621944 2020-11-10 stsp .right_path = path2,
261 1cb46f00 2020-11-21 stsp .flags = 0,
262 fe621944 2020-11-10 stsp };
263 fe621944 2020-11-10 stsp int rc;
264 fe621944 2020-11-10 stsp struct diff_output_info *output_info;
265 1cb46f00 2020-11-21 stsp
266 1cb46f00 2020-11-21 stsp if (!f1_exists)
267 1cb46f00 2020-11-21 stsp info.flags |= DIFF_INPUT_LEFT_NONEXISTENT;
268 1cb46f00 2020-11-21 stsp if (!f2_exists)
269 1cb46f00 2020-11-21 stsp info.flags |= DIFF_INPUT_RIGHT_NONEXISTENT;
270 574ed2c3 2017-11-29 stsp
271 fe621944 2020-11-10 stsp switch (output_format) {
272 fe621944 2020-11-10 stsp case GOT_DIFF_OUTPUT_UNIDIFF:
273 fe621944 2020-11-10 stsp rc = diff_output_unidiff(
274 c7d5c43c 2022-08-04 mark lines ? &output_info : NULL, outfile, &info,
275 fe621944 2020-11-10 stsp diff_result->result, context_lines);
276 fe621944 2020-11-10 stsp if (rc != DIFF_RC_OK)
277 fe621944 2020-11-10 stsp return got_error_set_errno(rc, "diff_output_unidiff");
278 fe621944 2020-11-10 stsp break;
279 d671c313 2022-09-02 stsp case GOT_DIFF_OUTPUT_PLAIN:
280 d671c313 2022-09-02 stsp rc = diff_output_plain(lines ? &output_info : NULL,
281 e72b0983 2022-09-03 stsp outfile, &info, diff_result->result, 1);
282 fe621944 2020-11-10 stsp if (rc != DIFF_RC_OK)
283 fe621944 2020-11-10 stsp return got_error_set_errno(rc, "diff_output_edscript");
284 fe621944 2020-11-10 stsp break;
285 fe621944 2020-11-10 stsp
286 574ed2c3 2017-11-29 stsp }
287 574ed2c3 2017-11-29 stsp
288 c7d5c43c 2022-08-04 mark if (lines && *lines) {
289 fe621944 2020-11-10 stsp if (output_info->line_offsets.len > 0) {
290 c7d5c43c 2022-08-04 mark struct got_diff_line *p;
291 c7d5c43c 2022-08-04 mark off_t prev_offset = 0, *o;
292 c7d5c43c 2022-08-04 mark uint8_t *o2;
293 fe621944 2020-11-10 stsp int i, len;
294 fe621944 2020-11-10 stsp if (*nlines > 0) {
295 c7d5c43c 2022-08-04 mark prev_offset = (*lines)[*nlines - 1].offset;
296 fe621944 2020-11-10 stsp /*
297 fe621944 2020-11-10 stsp * First line offset is always zero. Skip it
298 fe621944 2020-11-10 stsp * when appending to a pre-populated array.
299 fe621944 2020-11-10 stsp */
300 fe621944 2020-11-10 stsp o = &output_info->line_offsets.head[1];
301 c7d5c43c 2022-08-04 mark o2 = &output_info->line_types.head[1];
302 fe621944 2020-11-10 stsp len = output_info->line_offsets.len - 1;
303 fe621944 2020-11-10 stsp } else {
304 fe621944 2020-11-10 stsp o = &output_info->line_offsets.head[0];
305 c7d5c43c 2022-08-04 mark o2 = &output_info->line_types.head[0];
306 fe621944 2020-11-10 stsp len = output_info->line_offsets.len;
307 df51fc4e 2018-04-02 stsp }
308 c7d5c43c 2022-08-04 mark p = reallocarray(*lines, *nlines + len, sizeof(**lines));
309 fe621944 2020-11-10 stsp if (p == NULL)
310 fe621944 2020-11-10 stsp return got_error_from_errno("calloc");
311 c7d5c43c 2022-08-04 mark for (i = 0; i < len; i++) {
312 c7d5c43c 2022-08-04 mark p[*nlines + i].offset = o[i] + prev_offset;
313 c7d5c43c 2022-08-04 mark p[*nlines + i].type = o2[i];
314 c7d5c43c 2022-08-04 mark }
315 c7d5c43c 2022-08-04 mark *lines = p;
316 fe621944 2020-11-10 stsp *nlines += len;
317 574ed2c3 2017-11-29 stsp }
318 fe621944 2020-11-10 stsp diff_output_info_free(output_info);
319 574ed2c3 2017-11-29 stsp }
320 322260e1 2018-01-26 mpi
321 fe621944 2020-11-10 stsp return NULL;
322 574ed2c3 2017-11-29 stsp }
323 574ed2c3 2017-11-29 stsp
324 fe621944 2020-11-10 stsp const struct got_error *
325 fe621944 2020-11-10 stsp got_diffreg_result_free(struct got_diffreg_result *diffreg_result)
326 574ed2c3 2017-11-29 stsp {
327 fe621944 2020-11-10 stsp const struct got_error *err;
328 574ed2c3 2017-11-29 stsp
329 fe621944 2020-11-10 stsp diff_result_free(diffreg_result->result);
330 fe621944 2020-11-10 stsp diff_data_free(&diffreg_result->left);
331 fe621944 2020-11-10 stsp diff_data_free(&diffreg_result->right);
332 49d4a017 2022-06-30 stsp err = got_diffreg_close(diffreg_result->map1, diffreg_result->size1,
333 fe621944 2020-11-10 stsp diffreg_result->map2, diffreg_result->size2);
334 fe621944 2020-11-10 stsp free(diffreg_result);
335 fe621944 2020-11-10 stsp return err;
336 574ed2c3 2017-11-29 stsp }
337 574ed2c3 2017-11-29 stsp
338 fe621944 2020-11-10 stsp const struct got_error *
339 fe621944 2020-11-10 stsp got_diffreg_result_free_left(struct got_diffreg_result *diffreg_result)
340 574ed2c3 2017-11-29 stsp {
341 fe621944 2020-11-10 stsp diff_data_free(&diffreg_result->left);
342 fe621944 2020-11-10 stsp memset(&diffreg_result->left, 0, sizeof(diffreg_result->left));
343 49d4a017 2022-06-30 stsp return got_diffreg_close(diffreg_result->map1, diffreg_result->size1,
344 49d4a017 2022-06-30 stsp NULL, 0);
345 574ed2c3 2017-11-29 stsp }
346 574ed2c3 2017-11-29 stsp
347 fe621944 2020-11-10 stsp const struct got_error *
348 fe621944 2020-11-10 stsp got_diffreg_result_free_right(struct got_diffreg_result *diffreg_result)
349 574ed2c3 2017-11-29 stsp {
350 fe621944 2020-11-10 stsp diff_data_free(&diffreg_result->right);
351 fe621944 2020-11-10 stsp memset(&diffreg_result->right, 0, sizeof(diffreg_result->right));
352 49d4a017 2022-06-30 stsp return got_diffreg_close(NULL, 0, diffreg_result->map2,
353 49d4a017 2022-06-30 stsp diffreg_result->size2);
354 dc424a06 2019-08-07 stsp }