Blame


1 7d283eee 2017-11-29 stsp /*
2 7d283eee 2017-11-29 stsp * Copyright (c) 2017 Stefan Sperling <stsp@openbsd.org>
3 7d283eee 2017-11-29 stsp *
4 7d283eee 2017-11-29 stsp * Permission to use, copy, modify, and distribute this software for any
5 7d283eee 2017-11-29 stsp * purpose with or without fee is hereby granted, provided that the above
6 7d283eee 2017-11-29 stsp * copyright notice and this permission notice appear in all copies.
7 7d283eee 2017-11-29 stsp *
8 7d283eee 2017-11-29 stsp * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 7d283eee 2017-11-29 stsp * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 7d283eee 2017-11-29 stsp * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 7d283eee 2017-11-29 stsp * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 7d283eee 2017-11-29 stsp * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 7d283eee 2017-11-29 stsp * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 7d283eee 2017-11-29 stsp * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 7d283eee 2017-11-29 stsp */
16 7d283eee 2017-11-29 stsp
17 7d283eee 2017-11-29 stsp #include <sys/queue.h>
18 1c7f0520 2017-11-29 stsp #include <sys/stat.h>
19 7d283eee 2017-11-29 stsp
20 7d283eee 2017-11-29 stsp #include <stdio.h>
21 7d283eee 2017-11-29 stsp #include <stdlib.h>
22 7d283eee 2017-11-29 stsp #include <string.h>
23 f9d67749 2017-11-30 stsp #include <limits.h>
24 7d283eee 2017-11-29 stsp #include <sha1.h>
25 7d283eee 2017-11-29 stsp #include <zlib.h>
26 7d283eee 2017-11-29 stsp
27 7d283eee 2017-11-29 stsp #include "got_object.h"
28 e09a504c 2019-06-28 stsp #include "got_repository.h"
29 7d283eee 2017-11-29 stsp #include "got_error.h"
30 789689b5 2017-11-30 stsp #include "got_diff.h"
31 324d37e7 2019-05-11 stsp #include "got_path.h"
32 0208f208 2020-05-05 stsp #include "got_cancel.h"
33 0208f208 2020-05-05 stsp #include "got_worktree.h"
34 a558dd1b 2022-06-08 stsp #include "got_opentemp.h"
35 7d283eee 2017-11-29 stsp
36 718b3ab0 2018-03-17 stsp #include "got_lib_diff.h"
37 15a94983 2018-12-23 stsp #include "got_lib_delta.h"
38 15a94983 2018-12-23 stsp #include "got_lib_inflate.h"
39 15a94983 2018-12-23 stsp #include "got_lib_object.h"
40 a7852263 2017-11-30 stsp
41 404c43c4 2018-06-21 stsp static const struct got_error *
42 fe621944 2020-11-10 stsp add_line_offset(off_t **line_offsets, size_t *nlines, off_t off)
43 fe621944 2020-11-10 stsp {
44 fe621944 2020-11-10 stsp off_t *p;
45 fe621944 2020-11-10 stsp
46 fe621944 2020-11-10 stsp p = reallocarray(*line_offsets, *nlines + 1, sizeof(off_t));
47 fe621944 2020-11-10 stsp if (p == NULL)
48 fe621944 2020-11-10 stsp return got_error_from_errno("reallocarray");
49 fe621944 2020-11-10 stsp *line_offsets = p;
50 fe621944 2020-11-10 stsp (*line_offsets)[*nlines] = off;
51 fe621944 2020-11-10 stsp (*nlines)++;
52 fe621944 2020-11-10 stsp return NULL;
53 fe621944 2020-11-10 stsp }
54 fe621944 2020-11-10 stsp
55 fe621944 2020-11-10 stsp static const struct got_error *
56 fe621944 2020-11-10 stsp diff_blobs(off_t **line_offsets, size_t *nlines,
57 fe621944 2020-11-10 stsp struct got_diffreg_result **resultp, struct got_blob_object *blob1,
58 b72706c3 2022-06-01 stsp struct got_blob_object *blob2, FILE *f1, FILE *f2,
59 46f68b20 2019-10-19 stsp const char *label1, const char *label2, mode_t mode1, mode_t mode2,
60 64453f7e 2020-11-21 stsp int diff_context, int ignore_whitespace, int force_text_diff, FILE *outfile)
61 7d283eee 2017-11-29 stsp {
62 fe621944 2020-11-10 stsp const struct got_error *err = NULL, *free_err;
63 f78b0693 2017-11-29 stsp char hex1[SHA1_DIGEST_STRING_LENGTH];
64 f78b0693 2017-11-29 stsp char hex2[SHA1_DIGEST_STRING_LENGTH];
65 98abbc84 2017-11-30 stsp char *idstr1 = NULL, *idstr2 = NULL;
66 be659d10 2020-11-18 stsp off_t size1, size2;
67 fe621944 2020-11-10 stsp struct got_diffreg_result *result;
68 fe621944 2020-11-10 stsp off_t outoff = 0;
69 fe621944 2020-11-10 stsp int n;
70 7d283eee 2017-11-29 stsp
71 fe621944 2020-11-10 stsp if (line_offsets && *line_offsets && *nlines > 0)
72 fe621944 2020-11-10 stsp outoff = (*line_offsets)[*nlines - 1];
73 9c659ea0 2020-11-22 stsp else if (line_offsets) {
74 9c659ea0 2020-11-22 stsp err = add_line_offset(line_offsets, nlines, 0);
75 9c659ea0 2020-11-22 stsp if (err)
76 9c659ea0 2020-11-22 stsp goto done;
77 9c659ea0 2020-11-22 stsp }
78 fe621944 2020-11-10 stsp
79 fe621944 2020-11-10 stsp if (resultp)
80 fe621944 2020-11-10 stsp *resultp = NULL;
81 fe621944 2020-11-10 stsp
82 b72706c3 2022-06-01 stsp if (f1) {
83 a558dd1b 2022-06-08 stsp err = got_opentemp_truncate(f1);
84 b72706c3 2022-06-01 stsp if (err)
85 b72706c3 2022-06-01 stsp goto done;
86 fe621944 2020-11-10 stsp }
87 b72706c3 2022-06-01 stsp if (f2) {
88 a558dd1b 2022-06-08 stsp err = got_opentemp_truncate(f2);
89 b72706c3 2022-06-01 stsp if (err)
90 b72706c3 2022-06-01 stsp goto done;
91 fe621944 2020-11-10 stsp }
92 7d283eee 2017-11-29 stsp
93 f934cf2c 2018-02-12 stsp size1 = 0;
94 98abbc84 2017-11-30 stsp if (blob1) {
95 f934cf2c 2018-02-12 stsp idstr1 = got_object_blob_id_str(blob1, hex1, sizeof(hex1));
96 6c4c42e0 2019-06-24 stsp err = got_object_blob_dump_to_file(&size1, NULL, NULL, f1,
97 6c4c42e0 2019-06-24 stsp blob1);
98 35e9ba5d 2018-06-21 stsp if (err)
99 35e9ba5d 2018-06-21 stsp goto done;
100 98abbc84 2017-11-30 stsp } else
101 98abbc84 2017-11-30 stsp idstr1 = "/dev/null";
102 7d283eee 2017-11-29 stsp
103 f934cf2c 2018-02-12 stsp size2 = 0;
104 98abbc84 2017-11-30 stsp if (blob2) {
105 f934cf2c 2018-02-12 stsp idstr2 = got_object_blob_id_str(blob2, hex2, sizeof(hex2));
106 6c4c42e0 2019-06-24 stsp err = got_object_blob_dump_to_file(&size2, NULL, NULL, f2,
107 6c4c42e0 2019-06-24 stsp blob2);
108 35e9ba5d 2018-06-21 stsp if (err)
109 35e9ba5d 2018-06-21 stsp goto done;
110 98abbc84 2017-11-30 stsp } else
111 98abbc84 2017-11-30 stsp idstr2 = "/dev/null";
112 7d283eee 2017-11-29 stsp
113 09de383e 2018-12-24 stsp if (outfile) {
114 46f68b20 2019-10-19 stsp char *modestr1 = NULL, *modestr2 = NULL;
115 40dde666 2020-07-23 stsp int modebits;
116 46f68b20 2019-10-19 stsp if (mode1 && mode1 != mode2) {
117 40dde666 2020-07-23 stsp if (S_ISLNK(mode1))
118 40dde666 2020-07-23 stsp modebits = S_IFLNK;
119 40dde666 2020-07-23 stsp else
120 40dde666 2020-07-23 stsp modebits = (S_IRWXU | S_IRWXG | S_IRWXO);
121 46f68b20 2019-10-19 stsp if (asprintf(&modestr1, " (mode %o)",
122 40dde666 2020-07-23 stsp mode1 & modebits) == -1) {
123 46f68b20 2019-10-19 stsp err = got_error_from_errno("asprintf");
124 46f68b20 2019-10-19 stsp goto done;
125 46f68b20 2019-10-19 stsp }
126 46f68b20 2019-10-19 stsp }
127 46f68b20 2019-10-19 stsp if (mode2 && mode1 != mode2) {
128 40dde666 2020-07-23 stsp if (S_ISLNK(mode2))
129 40dde666 2020-07-23 stsp modebits = S_IFLNK;
130 40dde666 2020-07-23 stsp else
131 40dde666 2020-07-23 stsp modebits = (S_IRWXU | S_IRWXG | S_IRWXO);
132 46f68b20 2019-10-19 stsp if (asprintf(&modestr2, " (mode %o)",
133 40dde666 2020-07-23 stsp mode2 & modebits) == -1) {
134 46f68b20 2019-10-19 stsp err = got_error_from_errno("asprintf");
135 46f68b20 2019-10-19 stsp goto done;
136 46f68b20 2019-10-19 stsp }
137 46f68b20 2019-10-19 stsp }
138 fe621944 2020-11-10 stsp n = fprintf(outfile, "blob - %s%s\n", idstr1,
139 46f68b20 2019-10-19 stsp modestr1 ? modestr1 : "");
140 fe621944 2020-11-10 stsp if (n < 0)
141 fe621944 2020-11-10 stsp goto done;
142 fe621944 2020-11-10 stsp outoff += n;
143 fe621944 2020-11-10 stsp if (line_offsets) {
144 fe621944 2020-11-10 stsp err = add_line_offset(line_offsets, nlines, outoff);
145 fe621944 2020-11-10 stsp if (err)
146 fe621944 2020-11-10 stsp goto done;
147 fe621944 2020-11-10 stsp }
148 fe621944 2020-11-10 stsp
149 fe621944 2020-11-10 stsp n = fprintf(outfile, "blob + %s%s\n", idstr2,
150 46f68b20 2019-10-19 stsp modestr2 ? modestr2 : "");
151 fe621944 2020-11-10 stsp if (n < 0)
152 fe621944 2020-11-10 stsp goto done;
153 fe621944 2020-11-10 stsp outoff += n;
154 fe621944 2020-11-10 stsp if (line_offsets) {
155 fe621944 2020-11-10 stsp err = add_line_offset(line_offsets, nlines, outoff);
156 fe621944 2020-11-10 stsp if (err)
157 fe621944 2020-11-10 stsp goto done;
158 fe621944 2020-11-10 stsp }
159 fe621944 2020-11-10 stsp
160 46f68b20 2019-10-19 stsp free(modestr1);
161 46f68b20 2019-10-19 stsp free(modestr2);
162 09de383e 2018-12-24 stsp }
163 fe621944 2020-11-10 stsp err = got_diffreg(&result, f1, f2, GOT_DIFF_ALGORITHM_PATIENCE,
164 64453f7e 2020-11-21 stsp ignore_whitespace, force_text_diff);
165 fe621944 2020-11-10 stsp if (err)
166 fe621944 2020-11-10 stsp goto done;
167 fe621944 2020-11-10 stsp
168 fe621944 2020-11-10 stsp if (outfile) {
169 1cb46f00 2020-11-21 stsp err = got_diffreg_output(line_offsets, nlines, result,
170 1cb46f00 2020-11-21 stsp blob1 != NULL, blob2 != NULL,
171 fe621944 2020-11-10 stsp label1 ? label1 : idstr1,
172 fe621944 2020-11-10 stsp label2 ? label2 : idstr2,
173 fe621944 2020-11-10 stsp GOT_DIFF_OUTPUT_UNIDIFF, diff_context, outfile);
174 fe621944 2020-11-10 stsp if (err)
175 fe621944 2020-11-10 stsp goto done;
176 fe621944 2020-11-10 stsp }
177 fe621944 2020-11-10 stsp
178 fe621944 2020-11-10 stsp if (resultp && err == NULL)
179 fe621944 2020-11-10 stsp *resultp = result;
180 fe621944 2020-11-10 stsp else {
181 fe621944 2020-11-10 stsp free_err = got_diffreg_result_free(result);
182 fe621944 2020-11-10 stsp if (free_err && err == NULL)
183 fe621944 2020-11-10 stsp err = free_err;
184 fe621944 2020-11-10 stsp }
185 7d283eee 2017-11-29 stsp done:
186 7d283eee 2017-11-29 stsp return err;
187 aaa13589 2019-06-01 stsp }
188 aaa13589 2019-06-01 stsp
189 aaa13589 2019-06-01 stsp const struct got_error *
190 aaa13589 2019-06-01 stsp got_diff_blob_output_unidiff(void *arg, struct got_blob_object *blob1,
191 b72706c3 2022-06-01 stsp struct got_blob_object *blob2, FILE *f1, FILE *f2,
192 b72706c3 2022-06-01 stsp struct got_object_id *id1, struct got_object_id *id2,
193 b72706c3 2022-06-01 stsp const char *label1, const char *label2, mode_t mode1, mode_t mode2,
194 b72706c3 2022-06-01 stsp struct got_repository *repo)
195 aaa13589 2019-06-01 stsp {
196 aaa13589 2019-06-01 stsp struct got_diff_blob_output_unidiff_arg *a = arg;
197 aaa13589 2019-06-01 stsp
198 fe621944 2020-11-10 stsp return diff_blobs(&a->line_offsets, &a->nlines, NULL,
199 b72706c3 2022-06-01 stsp blob1, blob2, f1, f2, label1, label2, mode1, mode2, a->diff_context,
200 64453f7e 2020-11-21 stsp a->ignore_whitespace, a->force_text_diff, a->outfile);
201 7d283eee 2017-11-29 stsp }
202 474b4f94 2017-11-30 stsp
203 404c43c4 2018-06-21 stsp const struct got_error *
204 fe621944 2020-11-10 stsp got_diff_blob(off_t **line_offsets, size_t *nlines,
205 fe621944 2020-11-10 stsp struct got_blob_object *blob1, struct got_blob_object *blob2,
206 b72706c3 2022-06-01 stsp FILE *f1, FILE *f2, const char *label1, const char *label2,
207 b72706c3 2022-06-01 stsp int diff_context, int ignore_whitespace, int force_text_diff,
208 b72706c3 2022-06-01 stsp FILE *outfile)
209 404c43c4 2018-06-21 stsp {
210 b72706c3 2022-06-01 stsp return diff_blobs(line_offsets, nlines, NULL, blob1, blob2, f1, f2,
211 64453f7e 2020-11-21 stsp label1, label2, 0, 0, diff_context, ignore_whitespace,
212 64453f7e 2020-11-21 stsp force_text_diff, outfile);
213 404c43c4 2018-06-21 stsp }
214 404c43c4 2018-06-21 stsp
215 7f1f93af 2019-08-06 stsp static const struct got_error *
216 fe621944 2020-11-10 stsp diff_blob_file(struct got_diffreg_result **resultp,
217 b72706c3 2022-06-01 stsp struct got_blob_object *blob1, FILE *f1, off_t size1, const char *label1,
218 b72706c3 2022-06-01 stsp FILE *f2, size_t size2, const char *label2, int diff_context,
219 b72706c3 2022-06-01 stsp int ignore_whitespace, int force_text_diff, FILE *outfile)
220 b72f483a 2019-02-05 stsp {
221 fe621944 2020-11-10 stsp const struct got_error *err = NULL, *free_err;
222 b72f483a 2019-02-05 stsp char hex1[SHA1_DIGEST_STRING_LENGTH];
223 b72f483a 2019-02-05 stsp char *idstr1 = NULL;
224 fe621944 2020-11-10 stsp struct got_diffreg_result *result = NULL;
225 b72f483a 2019-02-05 stsp
226 fe621944 2020-11-10 stsp if (resultp)
227 fe621944 2020-11-10 stsp *resultp = NULL;
228 7f1f93af 2019-08-06 stsp
229 b72706c3 2022-06-01 stsp if (blob1)
230 b72f483a 2019-02-05 stsp idstr1 = got_object_blob_id_str(blob1, hex1, sizeof(hex1));
231 b72706c3 2022-06-01 stsp else
232 b72f483a 2019-02-05 stsp idstr1 = "/dev/null";
233 b72f483a 2019-02-05 stsp
234 7f1f93af 2019-08-06 stsp if (outfile) {
235 4ce46740 2019-08-08 stsp fprintf(outfile, "blob - %s\n", label1 ? label1 : idstr1);
236 7f1f93af 2019-08-06 stsp fprintf(outfile, "file + %s\n",
237 7f1f93af 2019-08-06 stsp f2 == NULL ? "/dev/null" : label2);
238 7f1f93af 2019-08-06 stsp }
239 fe621944 2020-11-10 stsp
240 fe621944 2020-11-10 stsp err = got_diffreg(&result, f1, f2, GOT_DIFF_ALGORITHM_PATIENCE,
241 64453f7e 2020-11-21 stsp ignore_whitespace, force_text_diff);
242 fe621944 2020-11-10 stsp if (err)
243 fe621944 2020-11-10 stsp goto done;
244 fe621944 2020-11-10 stsp
245 fe621944 2020-11-10 stsp if (outfile) {
246 1cb46f00 2020-11-21 stsp err = got_diffreg_output(NULL, NULL, result,
247 b72706c3 2022-06-01 stsp f1 != NULL, f2 != NULL,
248 1cb46f00 2020-11-21 stsp label2, /* show local file's path, not a blob ID */
249 1cb46f00 2020-11-21 stsp label2, GOT_DIFF_OUTPUT_UNIDIFF,
250 1cb46f00 2020-11-21 stsp diff_context, outfile);
251 7f1f93af 2019-08-06 stsp if (err)
252 fe621944 2020-11-10 stsp goto done;
253 7f1f93af 2019-08-06 stsp }
254 fe621944 2020-11-10 stsp
255 fe621944 2020-11-10 stsp if (resultp && err == NULL)
256 fe621944 2020-11-10 stsp *resultp = result;
257 fe621944 2020-11-10 stsp else if (result) {
258 fe621944 2020-11-10 stsp free_err = got_diffreg_result_free(result);
259 fe621944 2020-11-10 stsp if (free_err && err == NULL)
260 fe621944 2020-11-10 stsp err = free_err;
261 fe621944 2020-11-10 stsp }
262 b72f483a 2019-02-05 stsp done:
263 b72f483a 2019-02-05 stsp return err;
264 7f1f93af 2019-08-06 stsp }
265 7f1f93af 2019-08-06 stsp
266 7f1f93af 2019-08-06 stsp const struct got_error *
267 b72706c3 2022-06-01 stsp got_diff_blob_file(struct got_blob_object *blob1, FILE *f1, off_t size1,
268 b72706c3 2022-06-01 stsp const char *label1, FILE *f2, size_t size2, const char *label2,
269 b72706c3 2022-06-01 stsp int diff_context, int ignore_whitespace, int force_text_diff, FILE *outfile)
270 7f1f93af 2019-08-06 stsp {
271 b72706c3 2022-06-01 stsp return diff_blob_file(NULL, blob1, f1, size1, label1, f2, size2, label2,
272 64453f7e 2020-11-21 stsp diff_context, ignore_whitespace, force_text_diff, outfile);
273 474b4f94 2017-11-30 stsp }
274 474b4f94 2017-11-30 stsp
275 474b4f94 2017-11-30 stsp static const struct got_error *
276 b72706c3 2022-06-01 stsp diff_added_blob(struct got_object_id *id, FILE *f, const char *label,
277 b72706c3 2022-06-01 stsp mode_t mode, struct got_repository *repo,
278 b72706c3 2022-06-01 stsp got_diff_blob_cb cb, void *cb_arg)
279 474b4f94 2017-11-30 stsp {
280 4e22badc 2017-11-30 stsp const struct got_error *err;
281 2acfca77 2018-04-01 stsp struct got_blob_object *blob = NULL;
282 2acfca77 2018-04-01 stsp struct got_object *obj = NULL;
283 4e22badc 2017-11-30 stsp
284 4e22badc 2017-11-30 stsp err = got_object_open(&obj, repo, id);
285 4e22badc 2017-11-30 stsp if (err)
286 4e22badc 2017-11-30 stsp return err;
287 4e22badc 2017-11-30 stsp
288 2acfca77 2018-04-01 stsp err = got_object_blob_open(&blob, repo, obj, 8192);
289 2acfca77 2018-04-01 stsp if (err)
290 2acfca77 2018-04-01 stsp goto done;
291 b72706c3 2022-06-01 stsp err = cb(cb_arg, NULL, blob, NULL, f, NULL, id,
292 b72706c3 2022-06-01 stsp NULL, label, 0, mode, repo);
293 2acfca77 2018-04-01 stsp done:
294 2acfca77 2018-04-01 stsp got_object_close(obj);
295 2acfca77 2018-04-01 stsp if (blob)
296 2acfca77 2018-04-01 stsp got_object_blob_close(blob);
297 2acfca77 2018-04-01 stsp return err;
298 474b4f94 2017-11-30 stsp }
299 474b4f94 2017-11-30 stsp
300 474b4f94 2017-11-30 stsp static const struct got_error *
301 6a213ccb 2017-11-30 stsp diff_modified_blob(struct got_object_id *id1, struct got_object_id *id2,
302 b72706c3 2022-06-01 stsp FILE *f1, FILE *f2, const char *label1, const char *label2,
303 b72706c3 2022-06-01 stsp mode_t mode1, mode_t mode2, struct got_repository *repo,
304 b72706c3 2022-06-01 stsp got_diff_blob_cb cb, void *cb_arg)
305 474b4f94 2017-11-30 stsp {
306 6a213ccb 2017-11-30 stsp const struct got_error *err;
307 6a213ccb 2017-11-30 stsp struct got_object *obj1 = NULL;
308 6a213ccb 2017-11-30 stsp struct got_object *obj2 = NULL;
309 6a213ccb 2017-11-30 stsp struct got_blob_object *blob1 = NULL;
310 6a213ccb 2017-11-30 stsp struct got_blob_object *blob2 = NULL;
311 6a213ccb 2017-11-30 stsp
312 6a213ccb 2017-11-30 stsp err = got_object_open(&obj1, repo, id1);
313 6a213ccb 2017-11-30 stsp if (err)
314 730a8aa0 2018-04-24 stsp return err;
315 15a94983 2018-12-23 stsp if (obj1->type != GOT_OBJ_TYPE_BLOB) {
316 6a213ccb 2017-11-30 stsp err = got_error(GOT_ERR_OBJ_TYPE);
317 6a213ccb 2017-11-30 stsp goto done;
318 6a213ccb 2017-11-30 stsp }
319 6a213ccb 2017-11-30 stsp
320 6a213ccb 2017-11-30 stsp err = got_object_open(&obj2, repo, id2);
321 730a8aa0 2018-04-24 stsp if (err)
322 6a213ccb 2017-11-30 stsp goto done;
323 15a94983 2018-12-23 stsp if (obj2->type != GOT_OBJ_TYPE_BLOB) {
324 6a213ccb 2017-11-30 stsp err = got_error(GOT_ERR_BAD_OBJ_DATA);
325 6a213ccb 2017-11-30 stsp goto done;
326 6a213ccb 2017-11-30 stsp }
327 6a213ccb 2017-11-30 stsp
328 c7020aea 2017-11-30 stsp err = got_object_blob_open(&blob1, repo, obj1, 8192);
329 2acfca77 2018-04-01 stsp if (err)
330 6a213ccb 2017-11-30 stsp goto done;
331 6a213ccb 2017-11-30 stsp
332 c7020aea 2017-11-30 stsp err = got_object_blob_open(&blob2, repo, obj2, 8192);
333 2acfca77 2018-04-01 stsp if (err)
334 6a213ccb 2017-11-30 stsp goto done;
335 6a213ccb 2017-11-30 stsp
336 b72706c3 2022-06-01 stsp err = cb(cb_arg, blob1, blob2, f1, f2, id1, id2, label1, label2,
337 b72706c3 2022-06-01 stsp mode1, mode2, repo);
338 6a213ccb 2017-11-30 stsp done:
339 a3e2cbea 2017-12-01 stsp if (obj1)
340 a3e2cbea 2017-12-01 stsp got_object_close(obj1);
341 a3e2cbea 2017-12-01 stsp if (obj2)
342 a3e2cbea 2017-12-01 stsp got_object_close(obj2);
343 a3e2cbea 2017-12-01 stsp if (blob1)
344 a3e2cbea 2017-12-01 stsp got_object_blob_close(blob1);
345 a3e2cbea 2017-12-01 stsp if (blob2)
346 a3e2cbea 2017-12-01 stsp got_object_blob_close(blob2);
347 6a213ccb 2017-11-30 stsp return err;
348 474b4f94 2017-11-30 stsp }
349 474b4f94 2017-11-30 stsp
350 474b4f94 2017-11-30 stsp static const struct got_error *
351 b72706c3 2022-06-01 stsp diff_deleted_blob(struct got_object_id *id, FILE *f, const char *label,
352 b72706c3 2022-06-01 stsp mode_t mode, struct got_repository *repo, got_diff_blob_cb cb, void *cb_arg)
353 474b4f94 2017-11-30 stsp {
354 365fb436 2017-11-30 stsp const struct got_error *err;
355 2acfca77 2018-04-01 stsp struct got_blob_object *blob = NULL;
356 2acfca77 2018-04-01 stsp struct got_object *obj = NULL;
357 365fb436 2017-11-30 stsp
358 365fb436 2017-11-30 stsp err = got_object_open(&obj, repo, id);
359 365fb436 2017-11-30 stsp if (err)
360 365fb436 2017-11-30 stsp return err;
361 365fb436 2017-11-30 stsp
362 2acfca77 2018-04-01 stsp err = got_object_blob_open(&blob, repo, obj, 8192);
363 2acfca77 2018-04-01 stsp if (err)
364 2acfca77 2018-04-01 stsp goto done;
365 b72706c3 2022-06-01 stsp err = cb(cb_arg, blob, NULL, f, NULL, id, NULL, label, NULL,
366 b72706c3 2022-06-01 stsp mode, 0, repo);
367 2acfca77 2018-04-01 stsp done:
368 2acfca77 2018-04-01 stsp got_object_close(obj);
369 2acfca77 2018-04-01 stsp if (blob)
370 2acfca77 2018-04-01 stsp got_object_blob_close(blob);
371 2acfca77 2018-04-01 stsp return err;
372 474b4f94 2017-11-30 stsp }
373 474b4f94 2017-11-30 stsp
374 474b4f94 2017-11-30 stsp static const struct got_error *
375 b72706c3 2022-06-01 stsp diff_added_tree(struct got_object_id *id, FILE *f, const char *label,
376 31b4484f 2019-07-27 stsp struct got_repository *repo, got_diff_blob_cb cb, void *cb_arg,
377 31b4484f 2019-07-27 stsp int diff_content)
378 474b4f94 2017-11-30 stsp {
379 9c70d4c3 2017-11-30 stsp const struct got_error *err = NULL;
380 9c70d4c3 2017-11-30 stsp struct got_object *treeobj = NULL;
381 9c70d4c3 2017-11-30 stsp struct got_tree_object *tree = NULL;
382 9c70d4c3 2017-11-30 stsp
383 9c70d4c3 2017-11-30 stsp err = got_object_open(&treeobj, repo, id);
384 9c70d4c3 2017-11-30 stsp if (err)
385 9c70d4c3 2017-11-30 stsp goto done;
386 9c70d4c3 2017-11-30 stsp
387 15a94983 2018-12-23 stsp if (treeobj->type != GOT_OBJ_TYPE_TREE) {
388 9c70d4c3 2017-11-30 stsp err = got_error(GOT_ERR_OBJ_TYPE);
389 9c70d4c3 2017-11-30 stsp goto done;
390 9c70d4c3 2017-11-30 stsp }
391 9c70d4c3 2017-11-30 stsp
392 9c70d4c3 2017-11-30 stsp err = got_object_tree_open(&tree, repo, treeobj);
393 9c70d4c3 2017-11-30 stsp if (err)
394 9c70d4c3 2017-11-30 stsp goto done;
395 9c70d4c3 2017-11-30 stsp
396 b72706c3 2022-06-01 stsp err = got_diff_tree(NULL, tree, NULL, f, NULL, label,
397 b72706c3 2022-06-01 stsp repo, cb, cb_arg, diff_content);
398 9c70d4c3 2017-11-30 stsp done:
399 9c70d4c3 2017-11-30 stsp if (tree)
400 9c70d4c3 2017-11-30 stsp got_object_tree_close(tree);
401 9c70d4c3 2017-11-30 stsp if (treeobj)
402 9c70d4c3 2017-11-30 stsp got_object_close(treeobj);
403 9c70d4c3 2017-11-30 stsp return err;
404 474b4f94 2017-11-30 stsp }
405 474b4f94 2017-11-30 stsp
406 474b4f94 2017-11-30 stsp static const struct got_error *
407 789689b5 2017-11-30 stsp diff_modified_tree(struct got_object_id *id1, struct got_object_id *id2,
408 b72706c3 2022-06-01 stsp FILE *f1, FILE *f2, const char *label1, const char *label2,
409 b72706c3 2022-06-01 stsp struct got_repository *repo, got_diff_blob_cb cb, void *cb_arg,
410 b72706c3 2022-06-01 stsp int diff_content)
411 474b4f94 2017-11-30 stsp {
412 f6861a81 2018-09-13 stsp const struct got_error *err;
413 789689b5 2017-11-30 stsp struct got_object *treeobj1 = NULL;
414 789689b5 2017-11-30 stsp struct got_object *treeobj2 = NULL;
415 789689b5 2017-11-30 stsp struct got_tree_object *tree1 = NULL;
416 789689b5 2017-11-30 stsp struct got_tree_object *tree2 = NULL;
417 789689b5 2017-11-30 stsp
418 789689b5 2017-11-30 stsp err = got_object_open(&treeobj1, repo, id1);
419 789689b5 2017-11-30 stsp if (err)
420 789689b5 2017-11-30 stsp goto done;
421 789689b5 2017-11-30 stsp
422 15a94983 2018-12-23 stsp if (treeobj1->type != GOT_OBJ_TYPE_TREE) {
423 789689b5 2017-11-30 stsp err = got_error(GOT_ERR_OBJ_TYPE);
424 789689b5 2017-11-30 stsp goto done;
425 789689b5 2017-11-30 stsp }
426 789689b5 2017-11-30 stsp
427 789689b5 2017-11-30 stsp err = got_object_open(&treeobj2, repo, id2);
428 789689b5 2017-11-30 stsp if (err)
429 789689b5 2017-11-30 stsp goto done;
430 789689b5 2017-11-30 stsp
431 15a94983 2018-12-23 stsp if (treeobj2->type != GOT_OBJ_TYPE_TREE) {
432 789689b5 2017-11-30 stsp err = got_error(GOT_ERR_OBJ_TYPE);
433 789689b5 2017-11-30 stsp goto done;
434 789689b5 2017-11-30 stsp }
435 789689b5 2017-11-30 stsp
436 789689b5 2017-11-30 stsp err = got_object_tree_open(&tree1, repo, treeobj1);
437 789689b5 2017-11-30 stsp if (err)
438 789689b5 2017-11-30 stsp goto done;
439 789689b5 2017-11-30 stsp
440 789689b5 2017-11-30 stsp err = got_object_tree_open(&tree2, repo, treeobj2);
441 789689b5 2017-11-30 stsp if (err)
442 789689b5 2017-11-30 stsp goto done;
443 789689b5 2017-11-30 stsp
444 b72706c3 2022-06-01 stsp err = got_diff_tree(tree1, tree2, f1, f2, label1, label2,
445 b72706c3 2022-06-01 stsp repo, cb, cb_arg, diff_content);
446 789689b5 2017-11-30 stsp
447 789689b5 2017-11-30 stsp done:
448 789689b5 2017-11-30 stsp if (tree1)
449 789689b5 2017-11-30 stsp got_object_tree_close(tree1);
450 789689b5 2017-11-30 stsp if (tree2)
451 789689b5 2017-11-30 stsp got_object_tree_close(tree2);
452 789689b5 2017-11-30 stsp if (treeobj1)
453 789689b5 2017-11-30 stsp got_object_close(treeobj1);
454 789689b5 2017-11-30 stsp if (treeobj2)
455 789689b5 2017-11-30 stsp got_object_close(treeobj2);
456 789689b5 2017-11-30 stsp return err;
457 474b4f94 2017-11-30 stsp }
458 474b4f94 2017-11-30 stsp
459 474b4f94 2017-11-30 stsp static const struct got_error *
460 b72706c3 2022-06-01 stsp diff_deleted_tree(struct got_object_id *id, FILE *f, const char *label,
461 31b4484f 2019-07-27 stsp struct got_repository *repo, got_diff_blob_cb cb, void *cb_arg,
462 31b4484f 2019-07-27 stsp int diff_content)
463 474b4f94 2017-11-30 stsp {
464 f6861a81 2018-09-13 stsp const struct got_error *err;
465 2c56f2ce 2017-11-30 stsp struct got_object *treeobj = NULL;
466 2c56f2ce 2017-11-30 stsp struct got_tree_object *tree = NULL;
467 2c56f2ce 2017-11-30 stsp
468 2c56f2ce 2017-11-30 stsp err = got_object_open(&treeobj, repo, id);
469 2c56f2ce 2017-11-30 stsp if (err)
470 2c56f2ce 2017-11-30 stsp goto done;
471 2c56f2ce 2017-11-30 stsp
472 15a94983 2018-12-23 stsp if (treeobj->type != GOT_OBJ_TYPE_TREE) {
473 2c56f2ce 2017-11-30 stsp err = got_error(GOT_ERR_OBJ_TYPE);
474 2c56f2ce 2017-11-30 stsp goto done;
475 2c56f2ce 2017-11-30 stsp }
476 2c56f2ce 2017-11-30 stsp
477 2c56f2ce 2017-11-30 stsp err = got_object_tree_open(&tree, repo, treeobj);
478 2c56f2ce 2017-11-30 stsp if (err)
479 2c56f2ce 2017-11-30 stsp goto done;
480 2c56f2ce 2017-11-30 stsp
481 b72706c3 2022-06-01 stsp err = got_diff_tree(tree, NULL, f, NULL, label, NULL,
482 b72706c3 2022-06-01 stsp repo, cb, cb_arg, diff_content);
483 2c56f2ce 2017-11-30 stsp done:
484 2c56f2ce 2017-11-30 stsp if (tree)
485 2c56f2ce 2017-11-30 stsp got_object_tree_close(tree);
486 2c56f2ce 2017-11-30 stsp if (treeobj)
487 2c56f2ce 2017-11-30 stsp got_object_close(treeobj);
488 2c56f2ce 2017-11-30 stsp return err;
489 474b4f94 2017-11-30 stsp }
490 474b4f94 2017-11-30 stsp
491 474b4f94 2017-11-30 stsp static const struct got_error *
492 74671950 2018-02-11 stsp diff_kind_mismatch(struct got_object_id *id1, struct got_object_id *id2,
493 aaa13589 2019-06-01 stsp const char *label1, const char *label2, struct got_repository *repo,
494 aaa13589 2019-06-01 stsp got_diff_blob_cb cb, void *cb_arg)
495 474b4f94 2017-11-30 stsp {
496 013404a9 2017-11-30 stsp /* XXX TODO */
497 474b4f94 2017-11-30 stsp return NULL;
498 474b4f94 2017-11-30 stsp }
499 474b4f94 2017-11-30 stsp
500 474b4f94 2017-11-30 stsp static const struct got_error *
501 b72706c3 2022-06-01 stsp diff_entry_old_new(struct got_tree_entry *te1, struct got_tree_entry *te2,
502 b72706c3 2022-06-01 stsp FILE *f1, FILE *f2, const char *label1, const char *label2,
503 31b4484f 2019-07-27 stsp struct got_repository *repo, got_diff_blob_cb cb, void *cb_arg,
504 31b4484f 2019-07-27 stsp int diff_content)
505 474b4f94 2017-11-30 stsp {
506 f6861a81 2018-09-13 stsp const struct got_error *err = NULL;
507 19ae6da1 2018-11-05 stsp int id_match;
508 63c5ca5d 2019-08-24 stsp
509 63c5ca5d 2019-08-24 stsp if (got_object_tree_entry_is_submodule(te1))
510 63c5ca5d 2019-08-24 stsp return NULL;
511 474b4f94 2017-11-30 stsp
512 474b4f94 2017-11-30 stsp if (te2 == NULL) {
513 474b4f94 2017-11-30 stsp if (S_ISDIR(te1->mode))
514 b72706c3 2022-06-01 stsp err = diff_deleted_tree(&te1->id, f1, label1, repo,
515 31b4484f 2019-07-27 stsp cb, cb_arg, diff_content);
516 31b4484f 2019-07-27 stsp else {
517 31b4484f 2019-07-27 stsp if (diff_content)
518 b72706c3 2022-06-01 stsp err = diff_deleted_blob(&te1->id, f1, label1,
519 46f68b20 2019-10-19 stsp te1->mode, repo, cb, cb_arg);
520 31b4484f 2019-07-27 stsp else
521 b72706c3 2022-06-01 stsp err = cb(cb_arg, NULL, NULL, NULL, NULL,
522 b72706c3 2022-06-01 stsp &te1->id, NULL, label1, NULL,
523 b72706c3 2022-06-01 stsp te1->mode, 0, repo);
524 31b4484f 2019-07-27 stsp }
525 f6861a81 2018-09-13 stsp return err;
526 63c5ca5d 2019-08-24 stsp } else if (got_object_tree_entry_is_submodule(te2))
527 63c5ca5d 2019-08-24 stsp return NULL;
528 474b4f94 2017-11-30 stsp
529 56e0773d 2019-11-28 stsp id_match = (got_object_id_cmp(&te1->id, &te2->id) == 0);
530 4209f790 2017-11-30 stsp if (S_ISDIR(te1->mode) && S_ISDIR(te2->mode)) {
531 19ae6da1 2018-11-05 stsp if (!id_match)
532 b72706c3 2022-06-01 stsp return diff_modified_tree(&te1->id, &te2->id, f1, f2,
533 31b4484f 2019-07-27 stsp label1, label2, repo, cb, cb_arg, diff_content);
534 40dde666 2020-07-23 stsp } else if ((S_ISREG(te1->mode) || S_ISLNK(te1->mode)) &&
535 40dde666 2020-07-23 stsp (S_ISREG(te2->mode) || S_ISLNK(te2->mode))) {
536 46f68b20 2019-10-19 stsp if (!id_match ||
537 40dde666 2020-07-23 stsp ((te1->mode & (S_IFLNK | S_IXUSR))) !=
538 40dde666 2020-07-23 stsp (te2->mode & (S_IFLNK | S_IXUSR))) {
539 31b4484f 2019-07-27 stsp if (diff_content)
540 56e0773d 2019-11-28 stsp return diff_modified_blob(&te1->id, &te2->id,
541 b72706c3 2022-06-01 stsp f1, f2, label1, label2, te1->mode,
542 b72706c3 2022-06-01 stsp te2->mode, repo, cb, cb_arg);
543 31b4484f 2019-07-27 stsp else
544 b72706c3 2022-06-01 stsp return cb(cb_arg, NULL, NULL, NULL, NULL,
545 b72706c3 2022-06-01 stsp &te1->id, &te2->id, label1, label2,
546 b72706c3 2022-06-01 stsp te1->mode, te2->mode, repo);
547 31b4484f 2019-07-27 stsp }
548 413ea19d 2017-11-30 stsp }
549 474b4f94 2017-11-30 stsp
550 19ae6da1 2018-11-05 stsp if (id_match)
551 f6861a81 2018-09-13 stsp return NULL;
552 f6861a81 2018-09-13 stsp
553 56e0773d 2019-11-28 stsp return diff_kind_mismatch(&te1->id, &te2->id, label1, label2, repo,
554 aaa13589 2019-06-01 stsp cb, cb_arg);
555 474b4f94 2017-11-30 stsp }
556 474b4f94 2017-11-30 stsp
557 474b4f94 2017-11-30 stsp static const struct got_error *
558 56e0773d 2019-11-28 stsp diff_entry_new_old(struct got_tree_entry *te2,
559 b72706c3 2022-06-01 stsp struct got_tree_entry *te1, FILE *f2, const char *label2,
560 31b4484f 2019-07-27 stsp struct got_repository *repo, got_diff_blob_cb cb, void *cb_arg,
561 31b4484f 2019-07-27 stsp int diff_content)
562 474b4f94 2017-11-30 stsp {
563 f6861a81 2018-09-13 stsp if (te1 != NULL) /* handled by diff_entry_old_new() */
564 63c5ca5d 2019-08-24 stsp return NULL;
565 63c5ca5d 2019-08-24 stsp
566 63c5ca5d 2019-08-24 stsp if (got_object_tree_entry_is_submodule(te2))
567 f6861a81 2018-09-13 stsp return NULL;
568 474b4f94 2017-11-30 stsp
569 474b4f94 2017-11-30 stsp if (S_ISDIR(te2->mode))
570 b72706c3 2022-06-01 stsp return diff_added_tree(&te2->id, f2, label2,
571 b72706c3 2022-06-01 stsp repo, cb, cb_arg, diff_content);
572 f6861a81 2018-09-13 stsp
573 31b4484f 2019-07-27 stsp if (diff_content)
574 b72706c3 2022-06-01 stsp return diff_added_blob(&te2->id, f2, label2, te2->mode,
575 b72706c3 2022-06-01 stsp repo, cb, cb_arg);
576 31b4484f 2019-07-27 stsp
577 b72706c3 2022-06-01 stsp return cb(cb_arg, NULL, NULL, NULL, NULL, NULL, &te2->id,
578 b72706c3 2022-06-01 stsp NULL, label2, 0, te2->mode, repo);
579 0208f208 2020-05-05 stsp }
580 0208f208 2020-05-05 stsp
581 0208f208 2020-05-05 stsp const struct got_error *
582 0208f208 2020-05-05 stsp got_diff_tree_collect_changed_paths(void *arg, struct got_blob_object *blob1,
583 b72706c3 2022-06-01 stsp struct got_blob_object *blob2, FILE *f1, FILE *f2,
584 b72706c3 2022-06-01 stsp struct got_object_id *id1, struct got_object_id *id2,
585 b72706c3 2022-06-01 stsp const char *label1, const char *label2,
586 0208f208 2020-05-05 stsp mode_t mode1, mode_t mode2, struct got_repository *repo)
587 0208f208 2020-05-05 stsp {
588 0208f208 2020-05-05 stsp const struct got_error *err = NULL;
589 0208f208 2020-05-05 stsp struct got_pathlist_head *paths = arg;
590 0208f208 2020-05-05 stsp struct got_diff_changed_path *change = NULL;
591 0208f208 2020-05-05 stsp char *path = NULL;
592 0208f208 2020-05-05 stsp
593 0208f208 2020-05-05 stsp path = strdup(label2 ? label2 : label1);
594 0208f208 2020-05-05 stsp if (path == NULL)
595 0208f208 2020-05-05 stsp return got_error_from_errno("malloc");
596 0208f208 2020-05-05 stsp
597 0208f208 2020-05-05 stsp change = malloc(sizeof(*change));
598 0208f208 2020-05-05 stsp if (change == NULL) {
599 0208f208 2020-05-05 stsp err = got_error_from_errno("malloc");
600 0208f208 2020-05-05 stsp goto done;
601 0208f208 2020-05-05 stsp }
602 0208f208 2020-05-05 stsp
603 0208f208 2020-05-05 stsp change->status = GOT_STATUS_NO_CHANGE;
604 0208f208 2020-05-05 stsp if (id1 == NULL)
605 0208f208 2020-05-05 stsp change->status = GOT_STATUS_ADD;
606 0208f208 2020-05-05 stsp else if (id2 == NULL)
607 0208f208 2020-05-05 stsp change->status = GOT_STATUS_DELETE;
608 0208f208 2020-05-05 stsp else {
609 0208f208 2020-05-05 stsp if (got_object_id_cmp(id1, id2) != 0)
610 0208f208 2020-05-05 stsp change->status = GOT_STATUS_MODIFY;
611 0208f208 2020-05-05 stsp else if (mode1 != mode2)
612 0208f208 2020-05-05 stsp change->status = GOT_STATUS_MODE_CHANGE;
613 0208f208 2020-05-05 stsp }
614 0208f208 2020-05-05 stsp
615 46ea77db 2021-12-20 stsp err = got_pathlist_append(paths, path, change);
616 0208f208 2020-05-05 stsp done:
617 0208f208 2020-05-05 stsp if (err) {
618 0208f208 2020-05-05 stsp free(path);
619 0208f208 2020-05-05 stsp free(change);
620 0208f208 2020-05-05 stsp }
621 0208f208 2020-05-05 stsp return err;
622 474b4f94 2017-11-30 stsp }
623 474b4f94 2017-11-30 stsp
624 474b4f94 2017-11-30 stsp const struct got_error *
625 474b4f94 2017-11-30 stsp got_diff_tree(struct got_tree_object *tree1, struct got_tree_object *tree2,
626 b72706c3 2022-06-01 stsp FILE *f1, FILE *f2, const char *label1, const char *label2,
627 b72706c3 2022-06-01 stsp struct got_repository *repo, got_diff_blob_cb cb, void *cb_arg,
628 b72706c3 2022-06-01 stsp int diff_content)
629 474b4f94 2017-11-30 stsp {
630 474b4f94 2017-11-30 stsp const struct got_error *err = NULL;
631 789689b5 2017-11-30 stsp struct got_tree_entry *te1 = NULL;
632 789689b5 2017-11-30 stsp struct got_tree_entry *te2 = NULL;
633 f6861a81 2018-09-13 stsp char *l1 = NULL, *l2 = NULL;
634 56e0773d 2019-11-28 stsp int tidx1 = 0, tidx2 = 0;
635 474b4f94 2017-11-30 stsp
636 883f0469 2018-06-23 stsp if (tree1) {
637 56e0773d 2019-11-28 stsp te1 = got_object_tree_get_entry(tree1, 0);
638 60f50a58 2018-09-15 stsp if (te1 && asprintf(&l1, "%s%s%s", label1, label1[0] ? "/" : "",
639 f6861a81 2018-09-13 stsp te1->name) == -1)
640 638f9024 2019-05-13 stsp return got_error_from_errno("asprintf");
641 883f0469 2018-06-23 stsp }
642 883f0469 2018-06-23 stsp if (tree2) {
643 56e0773d 2019-11-28 stsp te2 = got_object_tree_get_entry(tree2, 0);
644 60f50a58 2018-09-15 stsp if (te2 && asprintf(&l2, "%s%s%s", label2, label2[0] ? "/" : "",
645 f6861a81 2018-09-13 stsp te2->name) == -1)
646 638f9024 2019-05-13 stsp return got_error_from_errno("asprintf");
647 883f0469 2018-06-23 stsp }
648 474b4f94 2017-11-30 stsp
649 474b4f94 2017-11-30 stsp do {
650 474b4f94 2017-11-30 stsp if (te1) {
651 56e0773d 2019-11-28 stsp struct got_tree_entry *te = NULL;
652 f6861a81 2018-09-13 stsp if (tree2)
653 1de5e065 2019-06-01 stsp te = got_object_tree_find_entry(tree2,
654 1de5e065 2019-06-01 stsp te1->name);
655 f6861a81 2018-09-13 stsp if (te) {
656 f6861a81 2018-09-13 stsp free(l2);
657 f6861a81 2018-09-13 stsp l2 = NULL;
658 f6861a81 2018-09-13 stsp if (te && asprintf(&l2, "%s%s%s", label2,
659 f6861a81 2018-09-13 stsp label2[0] ? "/" : "", te->name) == -1)
660 230a42bd 2019-05-11 jcs return
661 638f9024 2019-05-13 stsp got_error_from_errno("asprintf");
662 f6861a81 2018-09-13 stsp }
663 b72706c3 2022-06-01 stsp err = diff_entry_old_new(te1, te, f1, f2, l1, l2,
664 b72706c3 2022-06-01 stsp repo, cb, cb_arg, diff_content);
665 474b4f94 2017-11-30 stsp if (err)
666 474b4f94 2017-11-30 stsp break;
667 474b4f94 2017-11-30 stsp }
668 474b4f94 2017-11-30 stsp
669 474b4f94 2017-11-30 stsp if (te2) {
670 56e0773d 2019-11-28 stsp struct got_tree_entry *te = NULL;
671 f6861a81 2018-09-13 stsp if (tree1)
672 1de5e065 2019-06-01 stsp te = got_object_tree_find_entry(tree1,
673 1de5e065 2019-06-01 stsp te2->name);
674 d6ce02f1 2018-11-17 stsp free(l2);
675 d6ce02f1 2018-11-17 stsp if (te) {
676 d6ce02f1 2018-11-17 stsp if (asprintf(&l2, "%s%s%s", label2,
677 d6ce02f1 2018-11-17 stsp label2[0] ? "/" : "", te->name) == -1)
678 230a42bd 2019-05-11 jcs return
679 638f9024 2019-05-13 stsp got_error_from_errno("asprintf");
680 d6ce02f1 2018-11-17 stsp } else {
681 d6ce02f1 2018-11-17 stsp if (asprintf(&l2, "%s%s%s", label2,
682 d6ce02f1 2018-11-17 stsp label2[0] ? "/" : "", te2->name) == -1)
683 230a42bd 2019-05-11 jcs return
684 638f9024 2019-05-13 stsp got_error_from_errno("asprintf");
685 d6ce02f1 2018-11-17 stsp }
686 b72706c3 2022-06-01 stsp err = diff_entry_new_old(te2, te, f2, l2, repo,
687 31b4484f 2019-07-27 stsp cb, cb_arg, diff_content);
688 474b4f94 2017-11-30 stsp if (err)
689 474b4f94 2017-11-30 stsp break;
690 474b4f94 2017-11-30 stsp }
691 474b4f94 2017-11-30 stsp
692 f6861a81 2018-09-13 stsp free(l1);
693 f6861a81 2018-09-13 stsp l1 = NULL;
694 f6861a81 2018-09-13 stsp if (te1) {
695 56e0773d 2019-11-28 stsp tidx1++;
696 56e0773d 2019-11-28 stsp te1 = got_object_tree_get_entry(tree1, tidx1);
697 f6861a81 2018-09-13 stsp if (te1 &&
698 f6861a81 2018-09-13 stsp asprintf(&l1, "%s%s%s", label1,
699 f6861a81 2018-09-13 stsp label1[0] ? "/" : "", te1->name) == -1)
700 638f9024 2019-05-13 stsp return got_error_from_errno("asprintf");
701 f6861a81 2018-09-13 stsp }
702 f6861a81 2018-09-13 stsp free(l2);
703 f6861a81 2018-09-13 stsp l2 = NULL;
704 f6861a81 2018-09-13 stsp if (te2) {
705 56e0773d 2019-11-28 stsp tidx2++;
706 56e0773d 2019-11-28 stsp te2 = got_object_tree_get_entry(tree2, tidx2);
707 f6861a81 2018-09-13 stsp if (te2 &&
708 f6861a81 2018-09-13 stsp asprintf(&l2, "%s%s%s", label2,
709 f6861a81 2018-09-13 stsp label2[0] ? "/" : "", te2->name) == -1)
710 638f9024 2019-05-13 stsp return got_error_from_errno("asprintf");
711 f6861a81 2018-09-13 stsp }
712 474b4f94 2017-11-30 stsp } while (te1 || te2);
713 11528a82 2018-05-19 stsp
714 11528a82 2018-05-19 stsp return err;
715 11528a82 2018-05-19 stsp }
716 11528a82 2018-05-19 stsp
717 11528a82 2018-05-19 stsp const struct got_error *
718 fe621944 2020-11-10 stsp got_diff_objects_as_blobs(off_t **line_offsets, size_t *nlines,
719 b72706c3 2022-06-01 stsp FILE *f1, FILE *f2, struct got_object_id *id1, struct got_object_id *id2,
720 54156555 2018-12-24 stsp const char *label1, const char *label2, int diff_context,
721 64453f7e 2020-11-21 stsp int ignore_whitespace, int force_text_diff,
722 64453f7e 2020-11-21 stsp struct got_repository *repo, FILE *outfile)
723 11528a82 2018-05-19 stsp {
724 11528a82 2018-05-19 stsp const struct got_error *err;
725 11528a82 2018-05-19 stsp struct got_blob_object *blob1 = NULL, *blob2 = NULL;
726 b74c7625 2018-05-20 stsp
727 15a94983 2018-12-23 stsp if (id1 == NULL && id2 == NULL)
728 b74c7625 2018-05-20 stsp return got_error(GOT_ERR_NO_OBJ);
729 11528a82 2018-05-19 stsp
730 15a94983 2018-12-23 stsp if (id1) {
731 15a94983 2018-12-23 stsp err = got_object_open_as_blob(&blob1, repo, id1, 8192);
732 cd0acaa7 2018-05-20 stsp if (err)
733 cd0acaa7 2018-05-20 stsp goto done;
734 cd0acaa7 2018-05-20 stsp }
735 15a94983 2018-12-23 stsp if (id2) {
736 15a94983 2018-12-23 stsp err = got_object_open_as_blob(&blob2, repo, id2, 8192);
737 cd0acaa7 2018-05-20 stsp if (err)
738 cd0acaa7 2018-05-20 stsp goto done;
739 cd0acaa7 2018-05-20 stsp }
740 b72706c3 2022-06-01 stsp err = got_diff_blob(line_offsets, nlines, blob1, blob2, f1, f2,
741 64453f7e 2020-11-21 stsp label1, label2, diff_context, ignore_whitespace, force_text_diff,
742 64453f7e 2020-11-21 stsp outfile);
743 67b631c9 2021-10-10 stsp done:
744 67b631c9 2021-10-10 stsp if (blob1)
745 67b631c9 2021-10-10 stsp got_object_blob_close(blob1);
746 67b631c9 2021-10-10 stsp if (blob2)
747 67b631c9 2021-10-10 stsp got_object_blob_close(blob2);
748 67b631c9 2021-10-10 stsp return err;
749 67b631c9 2021-10-10 stsp }
750 67b631c9 2021-10-10 stsp
751 67b631c9 2021-10-10 stsp static const struct got_error *
752 67b631c9 2021-10-10 stsp diff_paths(struct got_tree_object *tree1, struct got_tree_object *tree2,
753 b72706c3 2022-06-01 stsp FILE *f1, FILE *f2, struct got_pathlist_head *paths,
754 b72706c3 2022-06-01 stsp struct got_repository *repo, got_diff_blob_cb cb, void *cb_arg)
755 67b631c9 2021-10-10 stsp {
756 67b631c9 2021-10-10 stsp const struct got_error *err = NULL;
757 67b631c9 2021-10-10 stsp struct got_pathlist_entry *pe;
758 67b631c9 2021-10-10 stsp struct got_object_id *id1 = NULL, *id2 = NULL;
759 67b631c9 2021-10-10 stsp struct got_tree_object *subtree1 = NULL, *subtree2 = NULL;
760 67b631c9 2021-10-10 stsp struct got_blob_object *blob1 = NULL, *blob2 = NULL;
761 67b631c9 2021-10-10 stsp
762 67b631c9 2021-10-10 stsp TAILQ_FOREACH(pe, paths, entry) {
763 67b631c9 2021-10-10 stsp int type1 = GOT_OBJ_TYPE_ANY, type2 = GOT_OBJ_TYPE_ANY;
764 67b631c9 2021-10-10 stsp mode_t mode1 = 0, mode2 = 0;
765 67b631c9 2021-10-10 stsp
766 67b631c9 2021-10-10 stsp free(id1);
767 67b631c9 2021-10-10 stsp id1 = NULL;
768 67b631c9 2021-10-10 stsp free(id2);
769 67b631c9 2021-10-10 stsp id2 = NULL;
770 67b631c9 2021-10-10 stsp if (subtree1) {
771 67b631c9 2021-10-10 stsp got_object_tree_close(subtree1);
772 67b631c9 2021-10-10 stsp subtree1 = NULL;
773 67b631c9 2021-10-10 stsp }
774 67b631c9 2021-10-10 stsp if (subtree2) {
775 67b631c9 2021-10-10 stsp got_object_tree_close(subtree2);
776 67b631c9 2021-10-10 stsp subtree2 = NULL;
777 67b631c9 2021-10-10 stsp }
778 67b631c9 2021-10-10 stsp if (blob1) {
779 67b631c9 2021-10-10 stsp got_object_blob_close(blob1);
780 67b631c9 2021-10-10 stsp blob1 = NULL;
781 67b631c9 2021-10-10 stsp }
782 67b631c9 2021-10-10 stsp if (blob2) {
783 67b631c9 2021-10-10 stsp got_object_blob_close(blob2);
784 67b631c9 2021-10-10 stsp blob2 = NULL;
785 67b631c9 2021-10-10 stsp }
786 67b631c9 2021-10-10 stsp
787 67b631c9 2021-10-10 stsp err = got_object_tree_find_path(&id1, &mode1, repo, tree1,
788 67b631c9 2021-10-10 stsp pe->path);
789 67b631c9 2021-10-10 stsp if (err && err->code != GOT_ERR_NO_TREE_ENTRY)
790 67b631c9 2021-10-10 stsp goto done;
791 67b631c9 2021-10-10 stsp err = got_object_tree_find_path(&id2, &mode2, repo, tree2,
792 67b631c9 2021-10-10 stsp pe->path);
793 67b631c9 2021-10-10 stsp if (err && err->code != GOT_ERR_NO_TREE_ENTRY)
794 67b631c9 2021-10-10 stsp goto done;
795 67b631c9 2021-10-10 stsp if (id1 == NULL && id2 == NULL) {
796 67b631c9 2021-10-10 stsp err = got_error_path(pe->path, GOT_ERR_NO_TREE_ENTRY);
797 67b631c9 2021-10-10 stsp goto done;
798 67b631c9 2021-10-10 stsp }
799 67b631c9 2021-10-10 stsp if (id1) {
800 67b631c9 2021-10-10 stsp err = got_object_get_type(&type1, repo, id1);
801 67b631c9 2021-10-10 stsp if (err)
802 67b631c9 2021-10-10 stsp goto done;
803 67b631c9 2021-10-10 stsp }
804 67b631c9 2021-10-10 stsp if (id2) {
805 67b631c9 2021-10-10 stsp err = got_object_get_type(&type2, repo, id2);
806 67b631c9 2021-10-10 stsp if (err)
807 67b631c9 2021-10-10 stsp goto done;
808 67b631c9 2021-10-10 stsp }
809 67b631c9 2021-10-10 stsp if (type1 == GOT_OBJ_TYPE_ANY &&
810 67b631c9 2021-10-10 stsp type2 == GOT_OBJ_TYPE_ANY) {
811 67b631c9 2021-10-10 stsp err = got_error_path(pe->path, GOT_ERR_NO_OBJ);
812 67b631c9 2021-10-10 stsp goto done;
813 67b631c9 2021-10-10 stsp } else if (type1 != GOT_OBJ_TYPE_ANY &&
814 67b631c9 2021-10-10 stsp type2 != GOT_OBJ_TYPE_ANY && type1 != type2) {
815 67b631c9 2021-10-10 stsp err = got_error(GOT_ERR_OBJ_TYPE);
816 67b631c9 2021-10-10 stsp goto done;
817 67b631c9 2021-10-10 stsp }
818 67b631c9 2021-10-10 stsp
819 67b631c9 2021-10-10 stsp if (type1 == GOT_OBJ_TYPE_BLOB ||
820 67b631c9 2021-10-10 stsp type2 == GOT_OBJ_TYPE_BLOB) {
821 67b631c9 2021-10-10 stsp if (id1) {
822 67b631c9 2021-10-10 stsp err = got_object_open_as_blob(&blob1, repo,
823 67b631c9 2021-10-10 stsp id1, 8192);
824 67b631c9 2021-10-10 stsp if (err)
825 67b631c9 2021-10-10 stsp goto done;
826 67b631c9 2021-10-10 stsp }
827 67b631c9 2021-10-10 stsp if (id2) {
828 67b631c9 2021-10-10 stsp err = got_object_open_as_blob(&blob2, repo,
829 67b631c9 2021-10-10 stsp id2, 8192);
830 67b631c9 2021-10-10 stsp if (err)
831 67b631c9 2021-10-10 stsp goto done;
832 67b631c9 2021-10-10 stsp }
833 b72706c3 2022-06-01 stsp err = cb(cb_arg, blob1, blob2, f1, f2, id1, id2,
834 67b631c9 2021-10-10 stsp id1 ? pe->path : "/dev/null",
835 67b631c9 2021-10-10 stsp id2 ? pe->path : "/dev/null",
836 67b631c9 2021-10-10 stsp mode1, mode2, repo);
837 67b631c9 2021-10-10 stsp if (err)
838 67b631c9 2021-10-10 stsp goto done;
839 67b631c9 2021-10-10 stsp } else if (type1 == GOT_OBJ_TYPE_TREE ||
840 67b631c9 2021-10-10 stsp type2 == GOT_OBJ_TYPE_TREE) {
841 67b631c9 2021-10-10 stsp if (id1) {
842 67b631c9 2021-10-10 stsp err = got_object_open_as_tree(&subtree1, repo,
843 67b631c9 2021-10-10 stsp id1);
844 67b631c9 2021-10-10 stsp if (err)
845 67b631c9 2021-10-10 stsp goto done;
846 67b631c9 2021-10-10 stsp }
847 67b631c9 2021-10-10 stsp if (id2) {
848 67b631c9 2021-10-10 stsp err = got_object_open_as_tree(&subtree2, repo,
849 67b631c9 2021-10-10 stsp id2);
850 67b631c9 2021-10-10 stsp if (err)
851 67b631c9 2021-10-10 stsp goto done;
852 67b631c9 2021-10-10 stsp }
853 b72706c3 2022-06-01 stsp err = got_diff_tree(subtree1, subtree2, f1, f2,
854 67b631c9 2021-10-10 stsp id1 ? pe->path : "/dev/null",
855 67b631c9 2021-10-10 stsp id2 ? pe->path : "/dev/null",
856 67b631c9 2021-10-10 stsp repo, cb, cb_arg, 1);
857 67b631c9 2021-10-10 stsp if (err)
858 67b631c9 2021-10-10 stsp goto done;
859 67b631c9 2021-10-10 stsp } else {
860 67b631c9 2021-10-10 stsp err = got_error(GOT_ERR_OBJ_TYPE);
861 67b631c9 2021-10-10 stsp goto done;
862 67b631c9 2021-10-10 stsp }
863 67b631c9 2021-10-10 stsp }
864 11528a82 2018-05-19 stsp done:
865 67b631c9 2021-10-10 stsp free(id1);
866 67b631c9 2021-10-10 stsp free(id2);
867 67b631c9 2021-10-10 stsp if (subtree1)
868 67b631c9 2021-10-10 stsp got_object_tree_close(subtree1);
869 67b631c9 2021-10-10 stsp if (subtree2)
870 67b631c9 2021-10-10 stsp got_object_tree_close(subtree2);
871 11528a82 2018-05-19 stsp if (blob1)
872 11528a82 2018-05-19 stsp got_object_blob_close(blob1);
873 11528a82 2018-05-19 stsp if (blob2)
874 11528a82 2018-05-19 stsp got_object_blob_close(blob2);
875 474b4f94 2017-11-30 stsp return err;
876 474b4f94 2017-11-30 stsp }
877 11528a82 2018-05-19 stsp
878 11528a82 2018-05-19 stsp const struct got_error *
879 fe621944 2020-11-10 stsp got_diff_objects_as_trees(off_t **line_offsets, size_t *nlines,
880 b72706c3 2022-06-01 stsp FILE *f1, FILE *f2, struct got_object_id *id1, struct got_object_id *id2,
881 67b631c9 2021-10-10 stsp struct got_pathlist_head *paths,
882 63035f9f 2019-10-06 stsp char *label1, char *label2, int diff_context, int ignore_whitespace,
883 64453f7e 2020-11-21 stsp int force_text_diff, struct got_repository *repo, FILE *outfile)
884 11528a82 2018-05-19 stsp {
885 11528a82 2018-05-19 stsp const struct got_error *err;
886 11528a82 2018-05-19 stsp struct got_tree_object *tree1 = NULL, *tree2 = NULL;
887 aaa13589 2019-06-01 stsp struct got_diff_blob_output_unidiff_arg arg;
888 fe621944 2020-11-10 stsp int want_lineoffsets = (line_offsets != NULL && *line_offsets != NULL);
889 11528a82 2018-05-19 stsp
890 15a94983 2018-12-23 stsp if (id1 == NULL && id2 == NULL)
891 b74c7625 2018-05-20 stsp return got_error(GOT_ERR_NO_OBJ);
892 b74c7625 2018-05-20 stsp
893 15a94983 2018-12-23 stsp if (id1) {
894 15a94983 2018-12-23 stsp err = got_object_open_as_tree(&tree1, repo, id1);
895 cd0acaa7 2018-05-20 stsp if (err)
896 cd0acaa7 2018-05-20 stsp goto done;
897 cd0acaa7 2018-05-20 stsp }
898 15a94983 2018-12-23 stsp if (id2) {
899 15a94983 2018-12-23 stsp err = got_object_open_as_tree(&tree2, repo, id2);
900 cd0acaa7 2018-05-20 stsp if (err)
901 cd0acaa7 2018-05-20 stsp goto done;
902 cd0acaa7 2018-05-20 stsp }
903 67b631c9 2021-10-10 stsp
904 aaa13589 2019-06-01 stsp arg.diff_context = diff_context;
905 63035f9f 2019-10-06 stsp arg.ignore_whitespace = ignore_whitespace;
906 64453f7e 2020-11-21 stsp arg.force_text_diff = force_text_diff;
907 aaa13589 2019-06-01 stsp arg.outfile = outfile;
908 fe621944 2020-11-10 stsp if (want_lineoffsets) {
909 fe621944 2020-11-10 stsp arg.line_offsets = *line_offsets;
910 fe621944 2020-11-10 stsp arg.nlines = *nlines;
911 fe621944 2020-11-10 stsp } else {
912 fe621944 2020-11-10 stsp arg.line_offsets = NULL;
913 fe621944 2020-11-10 stsp arg.nlines = 0;
914 fe621944 2020-11-10 stsp }
915 67b631c9 2021-10-10 stsp if (paths == NULL || TAILQ_EMPTY(paths)) {
916 b72706c3 2022-06-01 stsp err = got_diff_tree(tree1, tree2, f1, f2, label1, label2,
917 b72706c3 2022-06-01 stsp repo, got_diff_blob_output_unidiff, &arg, 1);
918 67b631c9 2021-10-10 stsp } else {
919 b72706c3 2022-06-01 stsp err = diff_paths(tree1, tree2, f1, f2, paths, repo,
920 67b631c9 2021-10-10 stsp got_diff_blob_output_unidiff, &arg);
921 67b631c9 2021-10-10 stsp }
922 fe621944 2020-11-10 stsp if (want_lineoffsets) {
923 fe621944 2020-11-10 stsp *line_offsets = arg.line_offsets; /* was likely re-allocated */
924 fe621944 2020-11-10 stsp *nlines = arg.nlines;
925 fe621944 2020-11-10 stsp }
926 11528a82 2018-05-19 stsp done:
927 11528a82 2018-05-19 stsp if (tree1)
928 11528a82 2018-05-19 stsp got_object_tree_close(tree1);
929 11528a82 2018-05-19 stsp if (tree2)
930 11528a82 2018-05-19 stsp got_object_tree_close(tree2);
931 11528a82 2018-05-19 stsp return err;
932 11528a82 2018-05-19 stsp }
933 11528a82 2018-05-19 stsp
934 11528a82 2018-05-19 stsp const struct got_error *
935 fe621944 2020-11-10 stsp got_diff_objects_as_commits(off_t **line_offsets, size_t *nlines,
936 b72706c3 2022-06-01 stsp FILE *f1, FILE *f2, struct got_object_id *id1, struct got_object_id *id2,
937 67b631c9 2021-10-10 stsp struct got_pathlist_head *paths,
938 64453f7e 2020-11-21 stsp int diff_context, int ignore_whitespace, int force_text_diff,
939 15a94983 2018-12-23 stsp struct got_repository *repo, FILE *outfile)
940 11528a82 2018-05-19 stsp {
941 11528a82 2018-05-19 stsp const struct got_error *err;
942 11528a82 2018-05-19 stsp struct got_commit_object *commit1 = NULL, *commit2 = NULL;
943 11528a82 2018-05-19 stsp
944 15a94983 2018-12-23 stsp if (id2 == NULL)
945 b74c7625 2018-05-20 stsp return got_error(GOT_ERR_NO_OBJ);
946 b74c7625 2018-05-20 stsp
947 15a94983 2018-12-23 stsp if (id1) {
948 15a94983 2018-12-23 stsp err = got_object_open_as_commit(&commit1, repo, id1);
949 cd0acaa7 2018-05-20 stsp if (err)
950 cd0acaa7 2018-05-20 stsp goto done;
951 cd0acaa7 2018-05-20 stsp }
952 bacc9935 2018-05-20 stsp
953 15a94983 2018-12-23 stsp err = got_object_open_as_commit(&commit2, repo, id2);
954 9b697879 2018-05-20 stsp if (err)
955 9b697879 2018-05-20 stsp goto done;
956 9b697879 2018-05-20 stsp
957 b72706c3 2022-06-01 stsp err = got_diff_objects_as_trees(line_offsets, nlines, f1, f2,
958 15a94983 2018-12-23 stsp commit1 ? got_object_commit_get_tree_id(commit1) : NULL,
959 67b631c9 2021-10-10 stsp got_object_commit_get_tree_id(commit2), paths, "", "",
960 67b631c9 2021-10-10 stsp diff_context, ignore_whitespace, force_text_diff, repo, outfile);
961 11528a82 2018-05-19 stsp done:
962 11528a82 2018-05-19 stsp if (commit1)
963 11528a82 2018-05-19 stsp got_object_commit_close(commit1);
964 11528a82 2018-05-19 stsp if (commit2)
965 11528a82 2018-05-19 stsp got_object_commit_close(commit2);
966 11528a82 2018-05-19 stsp return err;
967 11528a82 2018-05-19 stsp }
968 dc424a06 2019-08-07 stsp
969 dc424a06 2019-08-07 stsp const struct got_error *
970 fe621944 2020-11-10 stsp got_diff_files(struct got_diffreg_result **resultp,
971 fe621944 2020-11-10 stsp FILE *f1, const char *label1, FILE *f2, const char *label2,
972 64453f7e 2020-11-21 stsp int diff_context, int ignore_whitespace, int force_text_diff,
973 64453f7e 2020-11-21 stsp FILE *outfile)
974 dc424a06 2019-08-07 stsp {
975 dc424a06 2019-08-07 stsp const struct got_error *err = NULL;
976 fe621944 2020-11-10 stsp struct got_diffreg_result *diffreg_result = NULL;
977 dc424a06 2019-08-07 stsp
978 fe621944 2020-11-10 stsp if (resultp)
979 fe621944 2020-11-10 stsp *resultp = NULL;
980 dc424a06 2019-08-07 stsp
981 dc424a06 2019-08-07 stsp if (outfile) {
982 dc424a06 2019-08-07 stsp fprintf(outfile, "file - %s\n",
983 dc424a06 2019-08-07 stsp f1 == NULL ? "/dev/null" : label1);
984 dc424a06 2019-08-07 stsp fprintf(outfile, "file + %s\n",
985 dc424a06 2019-08-07 stsp f2 == NULL ? "/dev/null" : label2);
986 dc424a06 2019-08-07 stsp }
987 fe621944 2020-11-10 stsp
988 fe621944 2020-11-10 stsp err = got_diffreg(&diffreg_result, f1, f2, GOT_DIFF_ALGORITHM_PATIENCE,
989 64453f7e 2020-11-21 stsp ignore_whitespace, force_text_diff);
990 fe621944 2020-11-10 stsp if (err)
991 fe621944 2020-11-10 stsp goto done;
992 fe621944 2020-11-10 stsp
993 fe621944 2020-11-10 stsp if (outfile) {
994 fe621944 2020-11-10 stsp err = got_diffreg_output(NULL, NULL, diffreg_result,
995 1cb46f00 2020-11-21 stsp f1 != NULL, f2 != NULL, label1, label2,
996 1cb46f00 2020-11-21 stsp GOT_DIFF_OUTPUT_UNIDIFF, diff_context, outfile);
997 dc424a06 2019-08-07 stsp if (err)
998 dc424a06 2019-08-07 stsp goto done;
999 dc424a06 2019-08-07 stsp }
1000 fe621944 2020-11-10 stsp
1001 dc424a06 2019-08-07 stsp done:
1002 fe621944 2020-11-10 stsp if (resultp && err == NULL)
1003 fe621944 2020-11-10 stsp *resultp = diffreg_result;
1004 fe621944 2020-11-10 stsp else if (diffreg_result) {
1005 fe621944 2020-11-10 stsp const struct got_error *free_err;
1006 fe621944 2020-11-10 stsp free_err = got_diffreg_result_free(diffreg_result);
1007 fe621944 2020-11-10 stsp if (free_err && err == NULL)
1008 fe621944 2020-11-10 stsp err = free_err;
1009 dc424a06 2019-08-07 stsp }
1010 fe621944 2020-11-10 stsp
1011 dc424a06 2019-08-07 stsp return err;
1012 dc424a06 2019-08-07 stsp }