2 7d283eee 2017-11-29 stsp * Copyright (c) 2017 Stefan Sperling <stsp@openbsd.org>
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.
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.
17 7d283eee 2017-11-29 stsp #include <sys/queue.h>
18 1c7f0520 2017-11-29 stsp #include <sys/stat.h>
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>
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"
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"
42 5191b70b 2023-01-07 mark #define MAX(_a,_b) ((_a) > (_b) ? (_a) : (_b))
45 404c43c4 2018-06-21 stsp static const struct got_error *
46 c7d5c43c 2022-08-04 mark add_line_metadata(struct got_diff_line **lines, size_t *nlines,
47 c7d5c43c 2022-08-04 mark off_t off, uint8_t type)
49 c7d5c43c 2022-08-04 mark struct got_diff_line *p;
51 c7d5c43c 2022-08-04 mark p = reallocarray(*lines, *nlines + 1, sizeof(**lines));
52 fe621944 2020-11-10 stsp if (p == NULL)
53 fe621944 2020-11-10 stsp return got_error_from_errno("reallocarray");
55 c7d5c43c 2022-08-04 mark (*lines)[*nlines].offset = off;
56 c7d5c43c 2022-08-04 mark (*lines)[*nlines].type = type;
57 fe621944 2020-11-10 stsp (*nlines)++;
59 fe621944 2020-11-10 stsp return NULL;
63 a76e88e5 2023-01-10 mark diffstat_field_width(size_t *maxlen, int *add_cols, int *rm_cols, size_t len,
64 a76e88e5 2023-01-10 mark uint32_t add, uint32_t rm)
66 a76e88e5 2023-01-10 mark int d1 = 1, d2 = 1;
69 a76e88e5 2023-01-10 mark *maxlen = MAX(*maxlen, len);
71 a76e88e5 2023-01-10 mark while (add /= 10)
73 a76e88e5 2023-01-10 mark *add_cols = MAX(*add_cols, d1);
75 a76e88e5 2023-01-10 mark while (rm /= 10)
77 a76e88e5 2023-01-10 mark *rm_cols = MAX(*rm_cols, d2);
80 fe621944 2020-11-10 stsp static const struct got_error *
81 a76e88e5 2023-01-10 mark get_diffstat(struct got_diffstat_cb_arg *ds, const char *path,
82 a76e88e5 2023-01-10 mark struct diff_result *r, int force_text, int status)
84 a76e88e5 2023-01-10 mark const struct got_error *err;
85 a76e88e5 2023-01-10 mark struct got_pathlist_entry *pe;
86 a76e88e5 2023-01-10 mark struct got_diff_changed_path *change = NULL;
87 a76e88e5 2023-01-10 mark int flags = (r->left->atomizer_flags | r->right->atomizer_flags);
88 a76e88e5 2023-01-10 mark int isbin = (flags & DIFF_ATOMIZER_FOUND_BINARY_DATA);
91 a76e88e5 2023-01-10 mark change = calloc(1, sizeof(*change));
92 a76e88e5 2023-01-10 mark if (change == NULL)
93 a76e88e5 2023-01-10 mark return got_error_from_errno("malloc");
95 a76e88e5 2023-01-10 mark if (!isbin || force_text) {
96 a76e88e5 2023-01-10 mark for (i = 0; i < r->chunks.len; ++i) {
97 a76e88e5 2023-01-10 mark struct diff_chunk *c;
98 a76e88e5 2023-01-10 mark int clc, crc;
100 a76e88e5 2023-01-10 mark c = diff_chunk_get(r, i);
101 a76e88e5 2023-01-10 mark clc = diff_chunk_get_left_count(c);
102 a76e88e5 2023-01-10 mark crc = diff_chunk_get_right_count(c);
104 a76e88e5 2023-01-10 mark if (crc && !clc)
105 a76e88e5 2023-01-10 mark change->add += crc;
106 a76e88e5 2023-01-10 mark if (clc && !crc)
107 a76e88e5 2023-01-10 mark change->rm += clc;
111 a76e88e5 2023-01-10 mark change->status = status;
112 a76e88e5 2023-01-10 mark ds->ins += change->add;
113 a76e88e5 2023-01-10 mark ds->del += change->rm;
114 a76e88e5 2023-01-10 mark ++ds->nfiles;
116 a76e88e5 2023-01-10 mark err = got_pathlist_append(ds->paths, path, change);
118 a76e88e5 2023-01-10 mark return err;
120 a76e88e5 2023-01-10 mark pe = TAILQ_LAST(ds->paths, got_pathlist_head);
121 a76e88e5 2023-01-10 mark diffstat_field_width(&ds->max_path_len, &ds->add_cols, &ds->rm_cols,
122 a76e88e5 2023-01-10 mark pe->path_len, change->add, change->rm);
124 a76e88e5 2023-01-10 mark return NULL;
127 a76e88e5 2023-01-10 mark static const struct got_error *
128 c7d5c43c 2022-08-04 mark diff_blobs(struct got_diff_line **lines, size_t *nlines,
129 fe621944 2020-11-10 stsp struct got_diffreg_result **resultp, struct got_blob_object *blob1,
130 b72706c3 2022-06-01 stsp struct got_blob_object *blob2, FILE *f1, FILE *f2,
131 46f68b20 2019-10-19 stsp const char *label1, const char *label2, mode_t mode1, mode_t mode2,
132 a76e88e5 2023-01-10 mark int diff_context, int ignore_whitespace, int force_text_diff,
133 a76e88e5 2023-01-10 mark int show_diffstat, struct got_diffstat_cb_arg *ds, FILE *outfile,
134 4b752015 2022-06-30 stsp enum got_diff_algorithm diff_algo)
136 fe621944 2020-11-10 stsp const struct got_error *err = NULL, *free_err;
137 f78b0693 2017-11-29 stsp char hex1[SHA1_DIGEST_STRING_LENGTH];
138 f78b0693 2017-11-29 stsp char hex2[SHA1_DIGEST_STRING_LENGTH];
139 58e31a80 2022-06-27 op const char *idstr1 = NULL, *idstr2 = NULL;
140 be659d10 2020-11-18 stsp off_t size1, size2;
141 3846622f 2023-01-07 mark struct got_diffreg_result *result = NULL;
142 fe621944 2020-11-10 stsp off_t outoff = 0;
145 2d61e381 2022-08-30 mark if (lines && *lines && *nlines > 0)
146 c7d5c43c 2022-08-04 mark outoff = (*lines)[*nlines - 1].offset;
147 c7d5c43c 2022-08-04 mark else if (lines) {
148 c7d5c43c 2022-08-04 mark err = add_line_metadata(lines, nlines, 0, GOT_DIFF_LINE_NONE);
153 fe621944 2020-11-10 stsp if (resultp)
154 fe621944 2020-11-10 stsp *resultp = NULL;
157 a558dd1b 2022-06-08 stsp err = got_opentemp_truncate(f1);
162 a558dd1b 2022-06-08 stsp err = got_opentemp_truncate(f2);
168 98abbc84 2017-11-30 stsp if (blob1) {
169 f934cf2c 2018-02-12 stsp idstr1 = got_object_blob_id_str(blob1, hex1, sizeof(hex1));
170 6c4c42e0 2019-06-24 stsp err = got_object_blob_dump_to_file(&size1, NULL, NULL, f1,
175 98abbc84 2017-11-30 stsp idstr1 = "/dev/null";
178 98abbc84 2017-11-30 stsp if (blob2) {
179 f934cf2c 2018-02-12 stsp idstr2 = got_object_blob_id_str(blob2, hex2, sizeof(hex2));
180 6c4c42e0 2019-06-24 stsp err = got_object_blob_dump_to_file(&size2, NULL, NULL, f2,
185 98abbc84 2017-11-30 stsp idstr2 = "/dev/null";
187 09de383e 2018-12-24 stsp if (outfile) {
188 46f68b20 2019-10-19 stsp char *modestr1 = NULL, *modestr2 = NULL;
189 40dde666 2020-07-23 stsp int modebits;
190 46f68b20 2019-10-19 stsp if (mode1 && mode1 != mode2) {
191 40dde666 2020-07-23 stsp if (S_ISLNK(mode1))
192 40dde666 2020-07-23 stsp modebits = S_IFLNK;
194 40dde666 2020-07-23 stsp modebits = (S_IRWXU | S_IRWXG | S_IRWXO);
195 46f68b20 2019-10-19 stsp if (asprintf(&modestr1, " (mode %o)",
196 40dde666 2020-07-23 stsp mode1 & modebits) == -1) {
197 46f68b20 2019-10-19 stsp err = got_error_from_errno("asprintf");
201 46f68b20 2019-10-19 stsp if (mode2 && mode1 != mode2) {
202 40dde666 2020-07-23 stsp if (S_ISLNK(mode2))
203 40dde666 2020-07-23 stsp modebits = S_IFLNK;
205 40dde666 2020-07-23 stsp modebits = (S_IRWXU | S_IRWXG | S_IRWXO);
206 46f68b20 2019-10-19 stsp if (asprintf(&modestr2, " (mode %o)",
207 40dde666 2020-07-23 stsp mode2 & modebits) == -1) {
208 46f68b20 2019-10-19 stsp err = got_error_from_errno("asprintf");
212 fe621944 2020-11-10 stsp n = fprintf(outfile, "blob - %s%s\n", idstr1,
213 46f68b20 2019-10-19 stsp modestr1 ? modestr1 : "");
216 fe621944 2020-11-10 stsp outoff += n;
217 c7d5c43c 2022-08-04 mark if (lines) {
218 c7d5c43c 2022-08-04 mark err = add_line_metadata(lines, nlines, outoff,
219 c7d5c43c 2022-08-04 mark GOT_DIFF_LINE_BLOB_MIN);
224 fe621944 2020-11-10 stsp n = fprintf(outfile, "blob + %s%s\n", idstr2,
225 46f68b20 2019-10-19 stsp modestr2 ? modestr2 : "");
228 fe621944 2020-11-10 stsp outoff += n;
229 c7d5c43c 2022-08-04 mark if (lines) {
230 c7d5c43c 2022-08-04 mark err = add_line_metadata(lines, nlines, outoff,
231 c7d5c43c 2022-08-04 mark GOT_DIFF_LINE_BLOB_PLUS);
236 46f68b20 2019-10-19 stsp free(modestr1);
237 46f68b20 2019-10-19 stsp free(modestr2);
240 4b752015 2022-06-30 stsp err = got_diffreg(&result, f1, f2, diff_algo, ignore_whitespace,
241 4b752015 2022-06-30 stsp force_text_diff);
245 a76e88e5 2023-01-10 mark if (show_diffstat) {
246 a76e88e5 2023-01-10 mark char *path = NULL;
247 a76e88e5 2023-01-10 mark int status = GOT_STATUS_NO_CHANGE;
249 a76e88e5 2023-01-10 mark if (label1 == NULL && label2 == NULL) {
250 a76e88e5 2023-01-10 mark /* diffstat of blobs, show hash instead of path */
251 a76e88e5 2023-01-10 mark if (asprintf(&path, "%.10s -> %.10s",
252 a76e88e5 2023-01-10 mark idstr1, idstr2) == -1) {
253 a76e88e5 2023-01-10 mark err = got_error_from_errno("asprintf");
257 a76e88e5 2023-01-10 mark path = strdup(label2 ? label2 : label1);
258 a76e88e5 2023-01-10 mark if (path == NULL) {
259 a76e88e5 2023-01-10 mark err = got_error_from_errno("malloc");
265 a76e88e5 2023-01-10 mark * Ignore 'm'ode status change: if there's no accompanying
266 a76e88e5 2023-01-10 mark * content change, there'll be no diffstat, and if there
267 a76e88e5 2023-01-10 mark * are actual changes, 'M'odified takes precedence.
269 a76e88e5 2023-01-10 mark if (blob1 == NULL)
270 a76e88e5 2023-01-10 mark status = GOT_STATUS_ADD;
271 a76e88e5 2023-01-10 mark else if (blob2 == NULL)
272 a76e88e5 2023-01-10 mark status = GOT_STATUS_DELETE;
274 a76e88e5 2023-01-10 mark status = GOT_STATUS_MODIFY;
276 a76e88e5 2023-01-10 mark err = get_diffstat(ds, path, result->result, force_text_diff,
279 a76e88e5 2023-01-10 mark free(path);
284 fe621944 2020-11-10 stsp if (outfile) {
285 c7d5c43c 2022-08-04 mark err = got_diffreg_output(lines, nlines, result,
286 1cb46f00 2020-11-21 stsp blob1 != NULL, blob2 != NULL,
287 fe621944 2020-11-10 stsp label1 ? label1 : idstr1,
288 fe621944 2020-11-10 stsp label2 ? label2 : idstr2,
289 fe621944 2020-11-10 stsp GOT_DIFF_OUTPUT_UNIDIFF, diff_context, outfile);
295 fe621944 2020-11-10 stsp if (resultp && err == NULL)
296 fe621944 2020-11-10 stsp *resultp = result;
297 3846622f 2023-01-07 mark else if (result) {
298 fe621944 2020-11-10 stsp free_err = got_diffreg_result_free(result);
299 fe621944 2020-11-10 stsp if (free_err && err == NULL)
300 fe621944 2020-11-10 stsp err = free_err;
303 7d283eee 2017-11-29 stsp return err;
306 aaa13589 2019-06-01 stsp const struct got_error *
307 aaa13589 2019-06-01 stsp got_diff_blob_output_unidiff(void *arg, struct got_blob_object *blob1,
308 b72706c3 2022-06-01 stsp struct got_blob_object *blob2, FILE *f1, FILE *f2,
309 b72706c3 2022-06-01 stsp struct got_object_id *id1, struct got_object_id *id2,
310 b72706c3 2022-06-01 stsp const char *label1, const char *label2, mode_t mode1, mode_t mode2,
311 b72706c3 2022-06-01 stsp struct got_repository *repo)
313 aaa13589 2019-06-01 stsp struct got_diff_blob_output_unidiff_arg *a = arg;
315 c7d5c43c 2022-08-04 mark return diff_blobs(&a->lines, &a->nlines, NULL,
316 b72706c3 2022-06-01 stsp blob1, blob2, f1, f2, label1, label2, mode1, mode2, a->diff_context,
317 a76e88e5 2023-01-10 mark a->ignore_whitespace, a->force_text_diff, a->show_diffstat,
318 a76e88e5 2023-01-10 mark a->diffstat, a->outfile, a->diff_algo);
321 404c43c4 2018-06-21 stsp const struct got_error *
322 c7d5c43c 2022-08-04 mark got_diff_blob(struct got_diff_line **lines, size_t*nlines,
323 fe621944 2020-11-10 stsp struct got_blob_object *blob1, struct got_blob_object *blob2,
324 b72706c3 2022-06-01 stsp FILE *f1, FILE *f2, const char *label1, const char *label2,
325 4b752015 2022-06-30 stsp enum got_diff_algorithm diff_algo, int diff_context,
326 a76e88e5 2023-01-10 mark int ignore_whitespace, int force_text_diff, int show_diffstat,
327 a76e88e5 2023-01-10 mark struct got_diffstat_cb_arg *ds, FILE *outfile)
329 c7d5c43c 2022-08-04 mark return diff_blobs(lines, nlines, NULL, blob1, blob2, f1, f2,
330 64453f7e 2020-11-21 stsp label1, label2, 0, 0, diff_context, ignore_whitespace,
331 a76e88e5 2023-01-10 mark force_text_diff, show_diffstat, ds, outfile, diff_algo);
334 7f1f93af 2019-08-06 stsp static const struct got_error *
335 fe621944 2020-11-10 stsp diff_blob_file(struct got_diffreg_result **resultp,
336 b72706c3 2022-06-01 stsp struct got_blob_object *blob1, FILE *f1, off_t size1, const char *label1,
337 c87842d5 2022-09-23 mark FILE *f2, int f2_exists, struct stat *sb2, const char *label2,
338 4b752015 2022-06-30 stsp enum got_diff_algorithm diff_algo, int diff_context, int ignore_whitespace,
339 a76e88e5 2023-01-10 mark int force_text_diff, int show_diffstat, struct got_diffstat_cb_arg *ds,
340 a76e88e5 2023-01-10 mark FILE *outfile)
342 fe621944 2020-11-10 stsp const struct got_error *err = NULL, *free_err;
343 b72f483a 2019-02-05 stsp char hex1[SHA1_DIGEST_STRING_LENGTH];
344 58e31a80 2022-06-27 op const char *idstr1 = NULL;
345 fe621944 2020-11-10 stsp struct got_diffreg_result *result = NULL;
347 fe621944 2020-11-10 stsp if (resultp)
348 fe621944 2020-11-10 stsp *resultp = NULL;
351 b72f483a 2019-02-05 stsp idstr1 = got_object_blob_id_str(blob1, hex1, sizeof(hex1));
353 b72f483a 2019-02-05 stsp idstr1 = "/dev/null";
355 7f1f93af 2019-08-06 stsp if (outfile) {
356 c87842d5 2022-09-23 mark char *mode = NULL;
358 c87842d5 2022-09-23 mark /* display file mode for new added files only */
359 c87842d5 2022-09-23 mark if (f2_exists && blob1 == NULL) {
360 c87842d5 2022-09-23 mark int mmask = (S_IRWXU | S_IRWXG | S_IRWXO);
362 c87842d5 2022-09-23 mark if (S_ISLNK(sb2->st_mode))
363 c87842d5 2022-09-23 mark mmask = S_IFLNK;
364 c87842d5 2022-09-23 mark if (asprintf(&mode, " (mode %o)",
365 c87842d5 2022-09-23 mark sb2->st_mode & mmask) == -1)
366 c87842d5 2022-09-23 mark return got_error_from_errno("asprintf");
368 4ce46740 2019-08-08 stsp fprintf(outfile, "blob - %s\n", label1 ? label1 : idstr1);
369 c87842d5 2022-09-23 mark fprintf(outfile, "file + %s%s\n",
370 c87842d5 2022-09-23 mark f2_exists ? label2 : "/dev/null", mode ? mode : "");
371 c87842d5 2022-09-23 mark free(mode);
374 4b752015 2022-06-30 stsp err = got_diffreg(&result, f1, f2, diff_algo, ignore_whitespace,
375 4b752015 2022-06-30 stsp force_text_diff);
379 fe621944 2020-11-10 stsp if (outfile) {
380 1cb46f00 2020-11-21 stsp err = got_diffreg_output(NULL, NULL, result,
381 49d4a017 2022-06-30 stsp blob1 != NULL, f2_exists,
382 1cb46f00 2020-11-21 stsp label2, /* show local file's path, not a blob ID */
383 1cb46f00 2020-11-21 stsp label2, GOT_DIFF_OUTPUT_UNIDIFF,
384 1cb46f00 2020-11-21 stsp diff_context, outfile);
389 a76e88e5 2023-01-10 mark if (show_diffstat) {
390 a76e88e5 2023-01-10 mark char *path = NULL;
391 a76e88e5 2023-01-10 mark int status = GOT_STATUS_NO_CHANGE;
393 a76e88e5 2023-01-10 mark path = strdup(label2 ? label2 : label1);
394 a76e88e5 2023-01-10 mark if (path == NULL) {
395 a76e88e5 2023-01-10 mark err = got_error_from_errno("malloc");
400 a76e88e5 2023-01-10 mark * Ignore 'm'ode status change: if there's no accompanying
401 a76e88e5 2023-01-10 mark * content change, there'll be no diffstat, and if there
402 a76e88e5 2023-01-10 mark * are actual changes, 'M'odified takes precedence.
404 a76e88e5 2023-01-10 mark if (blob1 == NULL)
405 a76e88e5 2023-01-10 mark status = GOT_STATUS_ADD;
406 a76e88e5 2023-01-10 mark else if (!f2_exists)
407 a76e88e5 2023-01-10 mark status = GOT_STATUS_DELETE;
409 a76e88e5 2023-01-10 mark status = GOT_STATUS_MODIFY;
411 a76e88e5 2023-01-10 mark err = get_diffstat(ds, path, result->result, force_text_diff,
414 a76e88e5 2023-01-10 mark free(path);
420 fe621944 2020-11-10 stsp if (resultp && err == NULL)
421 fe621944 2020-11-10 stsp *resultp = result;
422 fe621944 2020-11-10 stsp else if (result) {
423 fe621944 2020-11-10 stsp free_err = got_diffreg_result_free(result);
424 fe621944 2020-11-10 stsp if (free_err && err == NULL)
425 fe621944 2020-11-10 stsp err = free_err;
427 b72f483a 2019-02-05 stsp return err;
430 7f1f93af 2019-08-06 stsp const struct got_error *
431 b72706c3 2022-06-01 stsp got_diff_blob_file(struct got_blob_object *blob1, FILE *f1, off_t size1,
432 c87842d5 2022-09-23 mark const char *label1, FILE *f2, int f2_exists, struct stat *sb2,
433 4b752015 2022-06-30 stsp const char *label2, enum got_diff_algorithm diff_algo, int diff_context,
434 a76e88e5 2023-01-10 mark int ignore_whitespace, int force_text_diff, int show_diffstat,
435 a76e88e5 2023-01-10 mark struct got_diffstat_cb_arg *ds, FILE *outfile)
437 49d4a017 2022-06-30 stsp return diff_blob_file(NULL, blob1, f1, size1, label1, f2, f2_exists,
438 c87842d5 2022-09-23 mark sb2, label2, diff_algo, diff_context, ignore_whitespace,
439 a76e88e5 2023-01-10 mark force_text_diff, show_diffstat, ds, outfile);
442 474b4f94 2017-11-30 stsp static const struct got_error *
443 49d4a017 2022-06-30 stsp diff_added_blob(struct got_object_id *id, FILE *f1, FILE *f2, int fd2,
444 f9d37699 2022-06-28 stsp const char *label, mode_t mode, struct got_repository *repo,
445 b72706c3 2022-06-01 stsp got_diff_blob_cb cb, void *cb_arg)
447 4e22badc 2017-11-30 stsp const struct got_error *err;
448 2acfca77 2018-04-01 stsp struct got_blob_object *blob = NULL;
449 2acfca77 2018-04-01 stsp struct got_object *obj = NULL;
451 4e22badc 2017-11-30 stsp err = got_object_open(&obj, repo, id);
453 4e22badc 2017-11-30 stsp return err;
455 49d4a017 2022-06-30 stsp err = got_object_blob_open(&blob, repo, obj, 8192, fd2);
458 49d4a017 2022-06-30 stsp err = cb(cb_arg, NULL, blob, f1, f2, NULL, id,
459 b72706c3 2022-06-01 stsp NULL, label, 0, mode, repo);
461 2acfca77 2018-04-01 stsp got_object_close(obj);
463 2acfca77 2018-04-01 stsp got_object_blob_close(blob);
464 2acfca77 2018-04-01 stsp return err;
467 474b4f94 2017-11-30 stsp static const struct got_error *
468 6a213ccb 2017-11-30 stsp diff_modified_blob(struct got_object_id *id1, struct got_object_id *id2,
469 f9d37699 2022-06-28 stsp FILE *f1, FILE *f2, int fd1, int fd2,
470 f9d37699 2022-06-28 stsp const char *label1, const char *label2,
471 b72706c3 2022-06-01 stsp mode_t mode1, mode_t mode2, struct got_repository *repo,
472 b72706c3 2022-06-01 stsp got_diff_blob_cb cb, void *cb_arg)
474 6a213ccb 2017-11-30 stsp const struct got_error *err;
475 6a213ccb 2017-11-30 stsp struct got_object *obj1 = NULL;
476 6a213ccb 2017-11-30 stsp struct got_object *obj2 = NULL;
477 6a213ccb 2017-11-30 stsp struct got_blob_object *blob1 = NULL;
478 6a213ccb 2017-11-30 stsp struct got_blob_object *blob2 = NULL;
480 6a213ccb 2017-11-30 stsp err = got_object_open(&obj1, repo, id1);
482 730a8aa0 2018-04-24 stsp return err;
484 15a94983 2018-12-23 stsp if (obj1->type != GOT_OBJ_TYPE_BLOB) {
485 6a213ccb 2017-11-30 stsp err = got_error(GOT_ERR_OBJ_TYPE);
489 6a213ccb 2017-11-30 stsp err = got_object_open(&obj2, repo, id2);
492 15a94983 2018-12-23 stsp if (obj2->type != GOT_OBJ_TYPE_BLOB) {
493 6a213ccb 2017-11-30 stsp err = got_error(GOT_ERR_BAD_OBJ_DATA);
497 eb81bc23 2022-06-28 tracey err = got_object_blob_open(&blob1, repo, obj1, 8192, fd1);
501 eb81bc23 2022-06-28 tracey err = got_object_blob_open(&blob2, repo, obj2, 8192, fd2);
505 b72706c3 2022-06-01 stsp err = cb(cb_arg, blob1, blob2, f1, f2, id1, id2, label1, label2,
506 b72706c3 2022-06-01 stsp mode1, mode2, repo);
509 a3e2cbea 2017-12-01 stsp got_object_close(obj1);
511 a3e2cbea 2017-12-01 stsp got_object_close(obj2);
513 a3e2cbea 2017-12-01 stsp got_object_blob_close(blob1);
515 a3e2cbea 2017-12-01 stsp got_object_blob_close(blob2);
516 6a213ccb 2017-11-30 stsp return err;
519 474b4f94 2017-11-30 stsp static const struct got_error *
520 49d4a017 2022-06-30 stsp diff_deleted_blob(struct got_object_id *id, FILE *f1, int fd1,
521 49d4a017 2022-06-30 stsp FILE *f2, const char *label, mode_t mode, struct got_repository *repo,
522 f9d37699 2022-06-28 stsp got_diff_blob_cb cb, void *cb_arg)
524 365fb436 2017-11-30 stsp const struct got_error *err;
525 2acfca77 2018-04-01 stsp struct got_blob_object *blob = NULL;
526 2acfca77 2018-04-01 stsp struct got_object *obj = NULL;
528 365fb436 2017-11-30 stsp err = got_object_open(&obj, repo, id);
530 365fb436 2017-11-30 stsp return err;
532 49d4a017 2022-06-30 stsp err = got_object_blob_open(&blob, repo, obj, 8192, fd1);
535 49d4a017 2022-06-30 stsp err = cb(cb_arg, blob, NULL, f1, f2, id, NULL, label, NULL,
536 b72706c3 2022-06-01 stsp mode, 0, repo);
538 2acfca77 2018-04-01 stsp got_object_close(obj);
540 2acfca77 2018-04-01 stsp got_object_blob_close(blob);
541 2acfca77 2018-04-01 stsp return err;
544 474b4f94 2017-11-30 stsp static const struct got_error *
545 49d4a017 2022-06-30 stsp diff_added_tree(struct got_object_id *id, FILE *f1, FILE *f2, int fd2,
546 49d4a017 2022-06-30 stsp const char *label, struct got_repository *repo, got_diff_blob_cb cb,
547 49d4a017 2022-06-30 stsp void *cb_arg, int diff_content)
549 9c70d4c3 2017-11-30 stsp const struct got_error *err = NULL;
550 9c70d4c3 2017-11-30 stsp struct got_object *treeobj = NULL;
551 9c70d4c3 2017-11-30 stsp struct got_tree_object *tree = NULL;
553 9c70d4c3 2017-11-30 stsp err = got_object_open(&treeobj, repo, id);
557 15a94983 2018-12-23 stsp if (treeobj->type != GOT_OBJ_TYPE_TREE) {
558 9c70d4c3 2017-11-30 stsp err = got_error(GOT_ERR_OBJ_TYPE);
562 9c70d4c3 2017-11-30 stsp err = got_object_tree_open(&tree, repo, treeobj);
566 49d4a017 2022-06-30 stsp err = got_diff_tree(NULL, tree, f1, f2, -1, fd2, NULL, label,
567 b72706c3 2022-06-01 stsp repo, cb, cb_arg, diff_content);
570 9c70d4c3 2017-11-30 stsp got_object_tree_close(tree);
571 9c70d4c3 2017-11-30 stsp if (treeobj)
572 9c70d4c3 2017-11-30 stsp got_object_close(treeobj);
573 9c70d4c3 2017-11-30 stsp return err;
576 474b4f94 2017-11-30 stsp static const struct got_error *
577 789689b5 2017-11-30 stsp diff_modified_tree(struct got_object_id *id1, struct got_object_id *id2,
578 f9d37699 2022-06-28 stsp FILE *f1, FILE *f2, int fd1, int fd2,
579 f9d37699 2022-06-28 stsp const char *label1, const char *label2,
580 b72706c3 2022-06-01 stsp struct got_repository *repo, got_diff_blob_cb cb, void *cb_arg,
581 b72706c3 2022-06-01 stsp int diff_content)
583 f6861a81 2018-09-13 stsp const struct got_error *err;
584 789689b5 2017-11-30 stsp struct got_object *treeobj1 = NULL;
585 789689b5 2017-11-30 stsp struct got_object *treeobj2 = NULL;
586 789689b5 2017-11-30 stsp struct got_tree_object *tree1 = NULL;
587 789689b5 2017-11-30 stsp struct got_tree_object *tree2 = NULL;
589 789689b5 2017-11-30 stsp err = got_object_open(&treeobj1, repo, id1);
593 15a94983 2018-12-23 stsp if (treeobj1->type != GOT_OBJ_TYPE_TREE) {
594 789689b5 2017-11-30 stsp err = got_error(GOT_ERR_OBJ_TYPE);
598 789689b5 2017-11-30 stsp err = got_object_open(&treeobj2, repo, id2);
602 15a94983 2018-12-23 stsp if (treeobj2->type != GOT_OBJ_TYPE_TREE) {
603 789689b5 2017-11-30 stsp err = got_error(GOT_ERR_OBJ_TYPE);
607 789689b5 2017-11-30 stsp err = got_object_tree_open(&tree1, repo, treeobj1);
611 789689b5 2017-11-30 stsp err = got_object_tree_open(&tree2, repo, treeobj2);
615 f9d37699 2022-06-28 stsp err = got_diff_tree(tree1, tree2, f1, f2, fd1, fd2,
616 f9d37699 2022-06-28 stsp label1, label2, repo, cb, cb_arg, diff_content);
620 789689b5 2017-11-30 stsp got_object_tree_close(tree1);
622 789689b5 2017-11-30 stsp got_object_tree_close(tree2);
623 789689b5 2017-11-30 stsp if (treeobj1)
624 789689b5 2017-11-30 stsp got_object_close(treeobj1);
625 789689b5 2017-11-30 stsp if (treeobj2)
626 789689b5 2017-11-30 stsp got_object_close(treeobj2);
627 789689b5 2017-11-30 stsp return err;
630 474b4f94 2017-11-30 stsp static const struct got_error *
631 49d4a017 2022-06-30 stsp diff_deleted_tree(struct got_object_id *id, FILE *f1, int fd1,
632 49d4a017 2022-06-30 stsp FILE *f2, const char *label, struct got_repository *repo,
633 f9d37699 2022-06-28 stsp got_diff_blob_cb cb, void *cb_arg, int diff_content)
635 f6861a81 2018-09-13 stsp const struct got_error *err;
636 2c56f2ce 2017-11-30 stsp struct got_object *treeobj = NULL;
637 2c56f2ce 2017-11-30 stsp struct got_tree_object *tree = NULL;
639 2c56f2ce 2017-11-30 stsp err = got_object_open(&treeobj, repo, id);
643 15a94983 2018-12-23 stsp if (treeobj->type != GOT_OBJ_TYPE_TREE) {
644 2c56f2ce 2017-11-30 stsp err = got_error(GOT_ERR_OBJ_TYPE);
648 2c56f2ce 2017-11-30 stsp err = got_object_tree_open(&tree, repo, treeobj);
652 49d4a017 2022-06-30 stsp err = got_diff_tree(tree, NULL, f1, f2, fd1, -1, label, NULL,
653 b72706c3 2022-06-01 stsp repo, cb, cb_arg, diff_content);
656 2c56f2ce 2017-11-30 stsp got_object_tree_close(tree);
657 2c56f2ce 2017-11-30 stsp if (treeobj)
658 2c56f2ce 2017-11-30 stsp got_object_close(treeobj);
659 2c56f2ce 2017-11-30 stsp return err;
662 474b4f94 2017-11-30 stsp static const struct got_error *
663 74671950 2018-02-11 stsp diff_kind_mismatch(struct got_object_id *id1, struct got_object_id *id2,
664 aaa13589 2019-06-01 stsp const char *label1, const char *label2, struct got_repository *repo,
665 aaa13589 2019-06-01 stsp got_diff_blob_cb cb, void *cb_arg)
667 013404a9 2017-11-30 stsp /* XXX TODO */
668 474b4f94 2017-11-30 stsp return NULL;
671 474b4f94 2017-11-30 stsp static const struct got_error *
672 b72706c3 2022-06-01 stsp diff_entry_old_new(struct got_tree_entry *te1, struct got_tree_entry *te2,
673 f9d37699 2022-06-28 stsp FILE *f1, FILE *f2, int fd1, int fd2,
674 f9d37699 2022-06-28 stsp const char *label1, const char *label2,
675 31b4484f 2019-07-27 stsp struct got_repository *repo, got_diff_blob_cb cb, void *cb_arg,
676 31b4484f 2019-07-27 stsp int diff_content)
678 f6861a81 2018-09-13 stsp const struct got_error *err = NULL;
679 19ae6da1 2018-11-05 stsp int id_match;
681 63c5ca5d 2019-08-24 stsp if (got_object_tree_entry_is_submodule(te1))
682 63c5ca5d 2019-08-24 stsp return NULL;
684 474b4f94 2017-11-30 stsp if (te2 == NULL) {
685 474b4f94 2017-11-30 stsp if (S_ISDIR(te1->mode))
686 49d4a017 2022-06-30 stsp err = diff_deleted_tree(&te1->id, f1, fd1, f2,
687 49d4a017 2022-06-30 stsp label1, repo, cb, cb_arg, diff_content);
689 31b4484f 2019-07-27 stsp if (diff_content)
690 f9d37699 2022-06-28 stsp err = diff_deleted_blob(&te1->id, f1, fd1,
691 49d4a017 2022-06-30 stsp f2, label1, te1->mode, repo, cb, cb_arg);
693 b72706c3 2022-06-01 stsp err = cb(cb_arg, NULL, NULL, NULL, NULL,
694 b72706c3 2022-06-01 stsp &te1->id, NULL, label1, NULL,
695 b72706c3 2022-06-01 stsp te1->mode, 0, repo);
697 f6861a81 2018-09-13 stsp return err;
698 63c5ca5d 2019-08-24 stsp } else if (got_object_tree_entry_is_submodule(te2))
699 63c5ca5d 2019-08-24 stsp return NULL;
701 56e0773d 2019-11-28 stsp id_match = (got_object_id_cmp(&te1->id, &te2->id) == 0);
702 4209f790 2017-11-30 stsp if (S_ISDIR(te1->mode) && S_ISDIR(te2->mode)) {
703 19ae6da1 2018-11-05 stsp if (!id_match)
704 b72706c3 2022-06-01 stsp return diff_modified_tree(&te1->id, &te2->id, f1, f2,
705 f9d37699 2022-06-28 stsp fd1, fd2, label1, label2, repo, cb, cb_arg,
706 f9d37699 2022-06-28 stsp diff_content);
707 40dde666 2020-07-23 stsp } else if ((S_ISREG(te1->mode) || S_ISLNK(te1->mode)) &&
708 40dde666 2020-07-23 stsp (S_ISREG(te2->mode) || S_ISLNK(te2->mode))) {
709 46f68b20 2019-10-19 stsp if (!id_match ||
710 40dde666 2020-07-23 stsp ((te1->mode & (S_IFLNK | S_IXUSR))) !=
711 40dde666 2020-07-23 stsp (te2->mode & (S_IFLNK | S_IXUSR))) {
712 31b4484f 2019-07-27 stsp if (diff_content)
713 56e0773d 2019-11-28 stsp return diff_modified_blob(&te1->id, &te2->id,
714 f9d37699 2022-06-28 stsp f1, f2, fd1, fd2, label1, label2,
715 f9d37699 2022-06-28 stsp te1->mode, te2->mode, repo, cb, cb_arg);
717 b72706c3 2022-06-01 stsp return cb(cb_arg, NULL, NULL, NULL, NULL,
718 b72706c3 2022-06-01 stsp &te1->id, &te2->id, label1, label2,
719 b72706c3 2022-06-01 stsp te1->mode, te2->mode, repo);
723 19ae6da1 2018-11-05 stsp if (id_match)
724 f6861a81 2018-09-13 stsp return NULL;
726 56e0773d 2019-11-28 stsp return diff_kind_mismatch(&te1->id, &te2->id, label1, label2, repo,
727 aaa13589 2019-06-01 stsp cb, cb_arg);
730 474b4f94 2017-11-30 stsp static const struct got_error *
731 56e0773d 2019-11-28 stsp diff_entry_new_old(struct got_tree_entry *te2,
732 49d4a017 2022-06-30 stsp struct got_tree_entry *te1, FILE *f1, FILE *f2, int fd2, const char *label2,
733 31b4484f 2019-07-27 stsp struct got_repository *repo, got_diff_blob_cb cb, void *cb_arg,
734 31b4484f 2019-07-27 stsp int diff_content)
736 f6861a81 2018-09-13 stsp if (te1 != NULL) /* handled by diff_entry_old_new() */
737 63c5ca5d 2019-08-24 stsp return NULL;
739 63c5ca5d 2019-08-24 stsp if (got_object_tree_entry_is_submodule(te2))
740 f6861a81 2018-09-13 stsp return NULL;
742 474b4f94 2017-11-30 stsp if (S_ISDIR(te2->mode))
743 49d4a017 2022-06-30 stsp return diff_added_tree(&te2->id, f1, f2, fd2, label2,
744 b72706c3 2022-06-01 stsp repo, cb, cb_arg, diff_content);
746 31b4484f 2019-07-27 stsp if (diff_content)
747 49d4a017 2022-06-30 stsp return diff_added_blob(&te2->id, f1, f2, fd2,
748 f9d37699 2022-06-28 stsp label2, te2->mode, repo, cb, cb_arg);
750 b72706c3 2022-06-01 stsp return cb(cb_arg, NULL, NULL, NULL, NULL, NULL, &te2->id,
751 b72706c3 2022-06-01 stsp NULL, label2, 0, te2->mode, repo);
754 0208f208 2020-05-05 stsp const struct got_error *
755 5191b70b 2023-01-07 mark got_diff_tree_compute_diffstat(void *arg, struct got_blob_object *blob1,
756 5191b70b 2023-01-07 mark struct got_blob_object *blob2, FILE *f1, FILE *f2,
757 5191b70b 2023-01-07 mark struct got_object_id *id1, struct got_object_id *id2,
758 5191b70b 2023-01-07 mark const char *label1, const char *label2,
759 5191b70b 2023-01-07 mark mode_t mode1, mode_t mode2, struct got_repository *repo)
761 5191b70b 2023-01-07 mark const struct got_error *err = NULL;
762 5191b70b 2023-01-07 mark struct got_diffreg_result *result = NULL;
763 5191b70b 2023-01-07 mark struct got_diffstat_cb_arg *a = arg;
764 5191b70b 2023-01-07 mark char *path = NULL;
765 a76e88e5 2023-01-10 mark int status = GOT_STATUS_NO_CHANGE;
767 5191b70b 2023-01-07 mark path = strdup(label2 ? label2 : label1);
768 5191b70b 2023-01-07 mark if (path == NULL)
769 5191b70b 2023-01-07 mark return got_error_from_errno("malloc");
771 5191b70b 2023-01-07 mark if (id1 == NULL)
772 a76e88e5 2023-01-10 mark status = GOT_STATUS_ADD;
773 5191b70b 2023-01-07 mark else if (id2 == NULL)
774 a76e88e5 2023-01-10 mark status = GOT_STATUS_DELETE;
776 5191b70b 2023-01-07 mark if (got_object_id_cmp(id1, id2) != 0)
777 a76e88e5 2023-01-10 mark status = GOT_STATUS_MODIFY;
778 5191b70b 2023-01-07 mark else if (mode1 != mode2)
779 a76e88e5 2023-01-10 mark status = GOT_STATUS_MODE_CHANGE;
783 5191b70b 2023-01-07 mark err = got_opentemp_truncate(f1);
788 5191b70b 2023-01-07 mark err = got_opentemp_truncate(f2);
793 5191b70b 2023-01-07 mark if (blob1) {
794 5191b70b 2023-01-07 mark err = got_object_blob_dump_to_file(NULL, NULL, NULL, f1,
799 5191b70b 2023-01-07 mark if (blob2) {
800 5191b70b 2023-01-07 mark err = got_object_blob_dump_to_file(NULL, NULL, NULL, f2,
806 5191b70b 2023-01-07 mark err = got_diffreg(&result, f1, f2, a->diff_algo, a->ignore_ws,
807 5191b70b 2023-01-07 mark a->force_text);
811 a76e88e5 2023-01-10 mark err = get_diffstat(a, path, result->result, a->force_text, status);
814 5191b70b 2023-01-07 mark if (result) {
815 5191b70b 2023-01-07 mark const struct got_error *free_err;
817 5191b70b 2023-01-07 mark free_err = got_diffreg_result_free(result);
818 5191b70b 2023-01-07 mark if (free_err && err == NULL)
819 5191b70b 2023-01-07 mark err = free_err;
822 5191b70b 2023-01-07 mark free(path);
823 5191b70b 2023-01-07 mark return err;
826 5191b70b 2023-01-07 mark const struct got_error *
827 0208f208 2020-05-05 stsp got_diff_tree_collect_changed_paths(void *arg, struct got_blob_object *blob1,
828 b72706c3 2022-06-01 stsp struct got_blob_object *blob2, FILE *f1, FILE *f2,
829 b72706c3 2022-06-01 stsp struct got_object_id *id1, struct got_object_id *id2,
830 b72706c3 2022-06-01 stsp const char *label1, const char *label2,
831 0208f208 2020-05-05 stsp mode_t mode1, mode_t mode2, struct got_repository *repo)
833 0208f208 2020-05-05 stsp const struct got_error *err = NULL;
834 0208f208 2020-05-05 stsp struct got_pathlist_head *paths = arg;
835 0208f208 2020-05-05 stsp struct got_diff_changed_path *change = NULL;
836 0208f208 2020-05-05 stsp char *path = NULL;
838 0208f208 2020-05-05 stsp path = strdup(label2 ? label2 : label1);
839 0208f208 2020-05-05 stsp if (path == NULL)
840 0208f208 2020-05-05 stsp return got_error_from_errno("malloc");
842 0208f208 2020-05-05 stsp change = malloc(sizeof(*change));
843 0208f208 2020-05-05 stsp if (change == NULL) {
844 0208f208 2020-05-05 stsp err = got_error_from_errno("malloc");
848 0208f208 2020-05-05 stsp change->status = GOT_STATUS_NO_CHANGE;
849 0208f208 2020-05-05 stsp if (id1 == NULL)
850 0208f208 2020-05-05 stsp change->status = GOT_STATUS_ADD;
851 0208f208 2020-05-05 stsp else if (id2 == NULL)
852 0208f208 2020-05-05 stsp change->status = GOT_STATUS_DELETE;
854 0208f208 2020-05-05 stsp if (got_object_id_cmp(id1, id2) != 0)
855 0208f208 2020-05-05 stsp change->status = GOT_STATUS_MODIFY;
856 0208f208 2020-05-05 stsp else if (mode1 != mode2)
857 0208f208 2020-05-05 stsp change->status = GOT_STATUS_MODE_CHANGE;
860 46ea77db 2021-12-20 stsp err = got_pathlist_append(paths, path, change);
863 0208f208 2020-05-05 stsp free(path);
864 0208f208 2020-05-05 stsp free(change);
866 0208f208 2020-05-05 stsp return err;
869 474b4f94 2017-11-30 stsp const struct got_error *
870 474b4f94 2017-11-30 stsp got_diff_tree(struct got_tree_object *tree1, struct got_tree_object *tree2,
871 f9d37699 2022-06-28 stsp FILE *f1, FILE *f2, int fd1, int fd2,
872 f9d37699 2022-06-28 stsp const char *label1, const char *label2,
873 b72706c3 2022-06-01 stsp struct got_repository *repo, got_diff_blob_cb cb, void *cb_arg,
874 b72706c3 2022-06-01 stsp int diff_content)
876 474b4f94 2017-11-30 stsp const struct got_error *err = NULL;
877 789689b5 2017-11-30 stsp struct got_tree_entry *te1 = NULL;
878 789689b5 2017-11-30 stsp struct got_tree_entry *te2 = NULL;
879 f6861a81 2018-09-13 stsp char *l1 = NULL, *l2 = NULL;
880 56e0773d 2019-11-28 stsp int tidx1 = 0, tidx2 = 0;
882 883f0469 2018-06-23 stsp if (tree1) {
883 56e0773d 2019-11-28 stsp te1 = got_object_tree_get_entry(tree1, 0);
884 60f50a58 2018-09-15 stsp if (te1 && asprintf(&l1, "%s%s%s", label1, label1[0] ? "/" : "",
885 f6861a81 2018-09-13 stsp te1->name) == -1)
886 638f9024 2019-05-13 stsp return got_error_from_errno("asprintf");
888 883f0469 2018-06-23 stsp if (tree2) {
889 56e0773d 2019-11-28 stsp te2 = got_object_tree_get_entry(tree2, 0);
890 60f50a58 2018-09-15 stsp if (te2 && asprintf(&l2, "%s%s%s", label2, label2[0] ? "/" : "",
891 f6861a81 2018-09-13 stsp te2->name) == -1)
892 638f9024 2019-05-13 stsp return got_error_from_errno("asprintf");
897 56e0773d 2019-11-28 stsp struct got_tree_entry *te = NULL;
899 1de5e065 2019-06-01 stsp te = got_object_tree_find_entry(tree2,
900 1de5e065 2019-06-01 stsp te1->name);
904 f6861a81 2018-09-13 stsp if (te && asprintf(&l2, "%s%s%s", label2,
905 f6861a81 2018-09-13 stsp label2[0] ? "/" : "", te->name) == -1)
907 638f9024 2019-05-13 stsp got_error_from_errno("asprintf");
909 f9d37699 2022-06-28 stsp err = diff_entry_old_new(te1, te, f1, f2, fd1, fd2,
910 f9d37699 2022-06-28 stsp l1, l2, repo, cb, cb_arg, diff_content);
916 56e0773d 2019-11-28 stsp struct got_tree_entry *te = NULL;
918 1de5e065 2019-06-01 stsp te = got_object_tree_find_entry(tree1,
919 1de5e065 2019-06-01 stsp te2->name);
922 d6ce02f1 2018-11-17 stsp if (asprintf(&l2, "%s%s%s", label2,
923 d6ce02f1 2018-11-17 stsp label2[0] ? "/" : "", te->name) == -1)
925 638f9024 2019-05-13 stsp got_error_from_errno("asprintf");
927 d6ce02f1 2018-11-17 stsp if (asprintf(&l2, "%s%s%s", label2,
928 d6ce02f1 2018-11-17 stsp label2[0] ? "/" : "", te2->name) == -1)
930 638f9024 2019-05-13 stsp got_error_from_errno("asprintf");
932 49d4a017 2022-06-30 stsp err = diff_entry_new_old(te2, te, f1, f2, fd2, l2,
933 49d4a017 2022-06-30 stsp repo, cb, cb_arg, diff_content);
942 56e0773d 2019-11-28 stsp te1 = got_object_tree_get_entry(tree1, tidx1);
944 f6861a81 2018-09-13 stsp asprintf(&l1, "%s%s%s", label1,
945 f6861a81 2018-09-13 stsp label1[0] ? "/" : "", te1->name) == -1)
946 638f9024 2019-05-13 stsp return got_error_from_errno("asprintf");
952 56e0773d 2019-11-28 stsp te2 = got_object_tree_get_entry(tree2, tidx2);
954 f6861a81 2018-09-13 stsp asprintf(&l2, "%s%s%s", label2,
955 f6861a81 2018-09-13 stsp label2[0] ? "/" : "", te2->name) == -1)
956 638f9024 2019-05-13 stsp return got_error_from_errno("asprintf");
958 474b4f94 2017-11-30 stsp } while (te1 || te2);
960 11528a82 2018-05-19 stsp return err;
963 11528a82 2018-05-19 stsp const struct got_error *
964 c7d5c43c 2022-08-04 mark got_diff_objects_as_blobs(struct got_diff_line **lines, size_t *nlines,
965 f9d37699 2022-06-28 stsp FILE *f1, FILE *f2, int fd1, int fd2,
966 f9d37699 2022-06-28 stsp struct got_object_id *id1, struct got_object_id *id2,
967 4b752015 2022-06-30 stsp const char *label1, const char *label2,
968 4b752015 2022-06-30 stsp enum got_diff_algorithm diff_algo, int diff_context,
969 a76e88e5 2023-01-10 mark int ignore_whitespace, int force_text_diff, int show_diffstat,
970 a76e88e5 2023-01-10 mark struct got_diffstat_cb_arg *ds, struct got_repository *repo, FILE *outfile)
972 11528a82 2018-05-19 stsp const struct got_error *err;
973 11528a82 2018-05-19 stsp struct got_blob_object *blob1 = NULL, *blob2 = NULL;
975 15a94983 2018-12-23 stsp if (id1 == NULL && id2 == NULL)
976 b74c7625 2018-05-20 stsp return got_error(GOT_ERR_NO_OBJ);
979 eb81bc23 2022-06-28 tracey err = got_object_open_as_blob(&blob1, repo, id1, 8192, fd1);
984 eb81bc23 2022-06-28 tracey err = got_object_open_as_blob(&blob2, repo, id2, 8192, fd2);
988 c7d5c43c 2022-08-04 mark err = got_diff_blob(lines, nlines, blob1, blob2, f1, f2, label1, label2,
989 c7d5c43c 2022-08-04 mark diff_algo, diff_context, ignore_whitespace, force_text_diff,
990 a76e88e5 2023-01-10 mark show_diffstat, ds, outfile);
993 67b631c9 2021-10-10 stsp got_object_blob_close(blob1);
995 67b631c9 2021-10-10 stsp got_object_blob_close(blob2);
996 67b631c9 2021-10-10 stsp return err;
999 67b631c9 2021-10-10 stsp static const struct got_error *
1000 67b631c9 2021-10-10 stsp diff_paths(struct got_tree_object *tree1, struct got_tree_object *tree2,
1001 f9d37699 2022-06-28 stsp FILE *f1, FILE *f2, int fd1, int fd2, struct got_pathlist_head *paths,
1002 b72706c3 2022-06-01 stsp struct got_repository *repo, got_diff_blob_cb cb, void *cb_arg)
1004 67b631c9 2021-10-10 stsp const struct got_error *err = NULL;
1005 67b631c9 2021-10-10 stsp struct got_pathlist_entry *pe;
1006 67b631c9 2021-10-10 stsp struct got_object_id *id1 = NULL, *id2 = NULL;
1007 67b631c9 2021-10-10 stsp struct got_tree_object *subtree1 = NULL, *subtree2 = NULL;
1008 67b631c9 2021-10-10 stsp struct got_blob_object *blob1 = NULL, *blob2 = NULL;
1010 67b631c9 2021-10-10 stsp TAILQ_FOREACH(pe, paths, entry) {
1011 67b631c9 2021-10-10 stsp int type1 = GOT_OBJ_TYPE_ANY, type2 = GOT_OBJ_TYPE_ANY;
1012 67b631c9 2021-10-10 stsp mode_t mode1 = 0, mode2 = 0;
1014 67b631c9 2021-10-10 stsp free(id1);
1015 67b631c9 2021-10-10 stsp id1 = NULL;
1016 67b631c9 2021-10-10 stsp free(id2);
1017 67b631c9 2021-10-10 stsp id2 = NULL;
1018 67b631c9 2021-10-10 stsp if (subtree1) {
1019 67b631c9 2021-10-10 stsp got_object_tree_close(subtree1);
1020 67b631c9 2021-10-10 stsp subtree1 = NULL;
1022 67b631c9 2021-10-10 stsp if (subtree2) {
1023 67b631c9 2021-10-10 stsp got_object_tree_close(subtree2);
1024 67b631c9 2021-10-10 stsp subtree2 = NULL;
1026 67b631c9 2021-10-10 stsp if (blob1) {
1027 67b631c9 2021-10-10 stsp got_object_blob_close(blob1);
1028 67b631c9 2021-10-10 stsp blob1 = NULL;
1030 67b631c9 2021-10-10 stsp if (blob2) {
1031 67b631c9 2021-10-10 stsp got_object_blob_close(blob2);
1032 67b631c9 2021-10-10 stsp blob2 = NULL;
1035 67b631c9 2021-10-10 stsp err = got_object_tree_find_path(&id1, &mode1, repo, tree1,
1036 67b631c9 2021-10-10 stsp pe->path);
1037 67b631c9 2021-10-10 stsp if (err && err->code != GOT_ERR_NO_TREE_ENTRY)
1038 67b631c9 2021-10-10 stsp goto done;
1039 67b631c9 2021-10-10 stsp err = got_object_tree_find_path(&id2, &mode2, repo, tree2,
1040 67b631c9 2021-10-10 stsp pe->path);
1041 67b631c9 2021-10-10 stsp if (err && err->code != GOT_ERR_NO_TREE_ENTRY)
1042 67b631c9 2021-10-10 stsp goto done;
1043 67b631c9 2021-10-10 stsp if (id1 == NULL && id2 == NULL) {
1044 67b631c9 2021-10-10 stsp err = got_error_path(pe->path, GOT_ERR_NO_TREE_ENTRY);
1045 67b631c9 2021-10-10 stsp goto done;
1047 67b631c9 2021-10-10 stsp if (id1) {
1048 67b631c9 2021-10-10 stsp err = got_object_get_type(&type1, repo, id1);
1050 67b631c9 2021-10-10 stsp goto done;
1052 67b631c9 2021-10-10 stsp if (id2) {
1053 67b631c9 2021-10-10 stsp err = got_object_get_type(&type2, repo, id2);
1055 67b631c9 2021-10-10 stsp goto done;
1057 67b631c9 2021-10-10 stsp if (type1 == GOT_OBJ_TYPE_ANY &&
1058 67b631c9 2021-10-10 stsp type2 == GOT_OBJ_TYPE_ANY) {
1059 67b631c9 2021-10-10 stsp err = got_error_path(pe->path, GOT_ERR_NO_OBJ);
1060 67b631c9 2021-10-10 stsp goto done;
1061 67b631c9 2021-10-10 stsp } else if (type1 != GOT_OBJ_TYPE_ANY &&
1062 67b631c9 2021-10-10 stsp type2 != GOT_OBJ_TYPE_ANY && type1 != type2) {
1063 67b631c9 2021-10-10 stsp err = got_error(GOT_ERR_OBJ_TYPE);
1064 67b631c9 2021-10-10 stsp goto done;
1067 67b631c9 2021-10-10 stsp if (type1 == GOT_OBJ_TYPE_BLOB ||
1068 67b631c9 2021-10-10 stsp type2 == GOT_OBJ_TYPE_BLOB) {
1069 67b631c9 2021-10-10 stsp if (id1) {
1070 67b631c9 2021-10-10 stsp err = got_object_open_as_blob(&blob1, repo,
1071 eb81bc23 2022-06-28 tracey id1, 8192, fd1);
1073 67b631c9 2021-10-10 stsp goto done;
1075 67b631c9 2021-10-10 stsp if (id2) {
1076 67b631c9 2021-10-10 stsp err = got_object_open_as_blob(&blob2, repo,
1077 eb81bc23 2022-06-28 tracey id2, 8192, fd2);
1079 67b631c9 2021-10-10 stsp goto done;
1081 b72706c3 2022-06-01 stsp err = cb(cb_arg, blob1, blob2, f1, f2, id1, id2,
1082 67b631c9 2021-10-10 stsp id1 ? pe->path : "/dev/null",
1083 67b631c9 2021-10-10 stsp id2 ? pe->path : "/dev/null",
1084 67b631c9 2021-10-10 stsp mode1, mode2, repo);
1086 67b631c9 2021-10-10 stsp goto done;
1087 67b631c9 2021-10-10 stsp } else if (type1 == GOT_OBJ_TYPE_TREE ||
1088 67b631c9 2021-10-10 stsp type2 == GOT_OBJ_TYPE_TREE) {
1089 67b631c9 2021-10-10 stsp if (id1) {
1090 67b631c9 2021-10-10 stsp err = got_object_open_as_tree(&subtree1, repo,
1093 67b631c9 2021-10-10 stsp goto done;
1095 67b631c9 2021-10-10 stsp if (id2) {
1096 67b631c9 2021-10-10 stsp err = got_object_open_as_tree(&subtree2, repo,
1099 67b631c9 2021-10-10 stsp goto done;
1101 b72706c3 2022-06-01 stsp err = got_diff_tree(subtree1, subtree2, f1, f2,
1103 67b631c9 2021-10-10 stsp id1 ? pe->path : "/dev/null",
1104 67b631c9 2021-10-10 stsp id2 ? pe->path : "/dev/null",
1105 67b631c9 2021-10-10 stsp repo, cb, cb_arg, 1);
1107 67b631c9 2021-10-10 stsp goto done;
1109 67b631c9 2021-10-10 stsp err = got_error(GOT_ERR_OBJ_TYPE);
1110 67b631c9 2021-10-10 stsp goto done;
1114 67b631c9 2021-10-10 stsp free(id1);
1115 67b631c9 2021-10-10 stsp free(id2);
1116 67b631c9 2021-10-10 stsp if (subtree1)
1117 67b631c9 2021-10-10 stsp got_object_tree_close(subtree1);
1118 67b631c9 2021-10-10 stsp if (subtree2)
1119 67b631c9 2021-10-10 stsp got_object_tree_close(subtree2);
1120 11528a82 2018-05-19 stsp if (blob1)
1121 11528a82 2018-05-19 stsp got_object_blob_close(blob1);
1122 11528a82 2018-05-19 stsp if (blob2)
1123 11528a82 2018-05-19 stsp got_object_blob_close(blob2);
1124 474b4f94 2017-11-30 stsp return err;
1127 8469d821 2022-06-25 stsp static const struct got_error *
1128 c7d5c43c 2022-08-04 mark show_object_id(struct got_diff_line **lines, size_t *nlines,
1129 c7d5c43c 2022-08-04 mark const char *obj_typestr, int ch, const char *id_str, FILE *outfile)
1131 8469d821 2022-06-25 stsp const struct got_error *err;
1133 8469d821 2022-06-25 stsp off_t outoff = 0;
1135 8469d821 2022-06-25 stsp n = fprintf(outfile, "%s %c %s\n", obj_typestr, ch, id_str);
1137 36e83e5e 2022-08-16 op return got_error_from_errno("fprintf");
1139 c7d5c43c 2022-08-04 mark if (lines != NULL && *lines != NULL) {
1140 8469d821 2022-06-25 stsp if (*nlines == 0) {
1141 c7d5c43c 2022-08-04 mark err = add_line_metadata(lines, nlines, 0,
1142 c7d5c43c 2022-08-04 mark GOT_DIFF_LINE_META);
1144 8469d821 2022-06-25 stsp return err;
1146 c7d5c43c 2022-08-04 mark outoff = (*lines)[*nlines - 1].offset;
1148 8469d821 2022-06-25 stsp outoff += n;
1149 c7d5c43c 2022-08-04 mark err = add_line_metadata(lines, nlines, outoff,
1150 c7d5c43c 2022-08-04 mark GOT_DIFF_LINE_META);
1152 8469d821 2022-06-25 stsp return err;
1155 8469d821 2022-06-25 stsp return NULL;
1158 8469d821 2022-06-25 stsp static const struct got_error *
1159 c7d5c43c 2022-08-04 mark diff_objects_as_trees(struct got_diff_line **lines, size_t *nlines,
1160 f9d37699 2022-06-28 stsp FILE *f1, FILE *f2, int fd1, int fd2,
1161 f9d37699 2022-06-28 stsp struct got_object_id *id1, struct got_object_id *id2,
1162 58e31a80 2022-06-27 op struct got_pathlist_head *paths, const char *label1, const char *label2,
1163 58e31a80 2022-06-27 op int diff_context, int ignore_whitespace, int force_text_diff,
1164 a76e88e5 2023-01-10 mark int show_diffstat, struct got_diffstat_cb_arg *dsa,
1165 4b752015 2022-06-30 stsp struct got_repository *repo, FILE *outfile,
1166 4b752015 2022-06-30 stsp enum got_diff_algorithm diff_algo)
1168 11528a82 2018-05-19 stsp const struct got_error *err;
1169 11528a82 2018-05-19 stsp struct got_tree_object *tree1 = NULL, *tree2 = NULL;
1170 aaa13589 2019-06-01 stsp struct got_diff_blob_output_unidiff_arg arg;
1171 c7d5c43c 2022-08-04 mark int want_linemeta = (lines != NULL && *lines != NULL);
1173 15a94983 2018-12-23 stsp if (id1 == NULL && id2 == NULL)
1174 b74c7625 2018-05-20 stsp return got_error(GOT_ERR_NO_OBJ);
1176 15a94983 2018-12-23 stsp if (id1) {
1177 15a94983 2018-12-23 stsp err = got_object_open_as_tree(&tree1, repo, id1);
1179 cd0acaa7 2018-05-20 stsp goto done;
1181 15a94983 2018-12-23 stsp if (id2) {
1182 15a94983 2018-12-23 stsp err = got_object_open_as_tree(&tree2, repo, id2);
1184 cd0acaa7 2018-05-20 stsp goto done;
1187 4b752015 2022-06-30 stsp arg.diff_algo = diff_algo;
1188 aaa13589 2019-06-01 stsp arg.diff_context = diff_context;
1189 63035f9f 2019-10-06 stsp arg.ignore_whitespace = ignore_whitespace;
1190 64453f7e 2020-11-21 stsp arg.force_text_diff = force_text_diff;
1191 a76e88e5 2023-01-10 mark arg.show_diffstat = show_diffstat;
1192 a76e88e5 2023-01-10 mark arg.diffstat = dsa;
1193 aaa13589 2019-06-01 stsp arg.outfile = outfile;
1194 c7d5c43c 2022-08-04 mark if (want_linemeta) {
1195 c7d5c43c 2022-08-04 mark arg.lines = *lines;
1196 fe621944 2020-11-10 stsp arg.nlines = *nlines;
1198 c7d5c43c 2022-08-04 mark arg.lines = NULL;
1199 fe621944 2020-11-10 stsp arg.nlines = 0;
1201 a76e88e5 2023-01-10 mark if (paths == NULL || TAILQ_EMPTY(paths))
1202 a76e88e5 2023-01-10 mark err = got_diff_tree(tree1, tree2, f1, f2, fd1, fd2, label1,
1203 a76e88e5 2023-01-10 mark label2, repo, got_diff_blob_output_unidiff, &arg, 1);
1205 f9d37699 2022-06-28 stsp err = diff_paths(tree1, tree2, f1, f2, fd1, fd2, paths, repo,
1206 67b631c9 2021-10-10 stsp got_diff_blob_output_unidiff, &arg);
1207 c7d5c43c 2022-08-04 mark if (want_linemeta) {
1208 c7d5c43c 2022-08-04 mark *lines = arg.lines; /* was likely re-allocated */
1209 fe621944 2020-11-10 stsp *nlines = arg.nlines;
1212 11528a82 2018-05-19 stsp if (tree1)
1213 11528a82 2018-05-19 stsp got_object_tree_close(tree1);
1214 11528a82 2018-05-19 stsp if (tree2)
1215 11528a82 2018-05-19 stsp got_object_tree_close(tree2);
1216 11528a82 2018-05-19 stsp return err;
1219 11528a82 2018-05-19 stsp const struct got_error *
1220 c7d5c43c 2022-08-04 mark got_diff_objects_as_trees(struct got_diff_line **lines, size_t *nlines,
1221 f9d37699 2022-06-28 stsp FILE *f1, FILE *f2, int fd1, int fd2,
1222 f9d37699 2022-06-28 stsp struct got_object_id *id1, struct got_object_id *id2,
1223 58e31a80 2022-06-27 op struct got_pathlist_head *paths, const char *label1, const char *label2,
1224 4b752015 2022-06-30 stsp enum got_diff_algorithm diff_algo, int diff_context, int ignore_whitespace,
1225 a76e88e5 2023-01-10 mark int force_text_diff, int show_diffstat, struct got_diffstat_cb_arg *dsa,
1226 a76e88e5 2023-01-10 mark struct got_repository *repo, FILE *outfile)
1228 8469d821 2022-06-25 stsp const struct got_error *err;
1229 8469d821 2022-06-25 stsp char *idstr = NULL;
1231 8469d821 2022-06-25 stsp if (id1 == NULL && id2 == NULL)
1232 8469d821 2022-06-25 stsp return got_error(GOT_ERR_NO_OBJ);
1234 8469d821 2022-06-25 stsp if (id1) {
1235 8469d821 2022-06-25 stsp err = got_object_id_str(&idstr, id1);
1237 8469d821 2022-06-25 stsp goto done;
1238 c7d5c43c 2022-08-04 mark err = show_object_id(lines, nlines, "tree", '-', idstr, outfile);
1240 8469d821 2022-06-25 stsp goto done;
1241 8469d821 2022-06-25 stsp free(idstr);
1242 8469d821 2022-06-25 stsp idstr = NULL;
1244 c7d5c43c 2022-08-04 mark err = show_object_id(lines, nlines, "tree", '-', "/dev/null",
1247 8469d821 2022-06-25 stsp goto done;
1250 8469d821 2022-06-25 stsp if (id2) {
1251 8469d821 2022-06-25 stsp err = got_object_id_str(&idstr, id2);
1253 8469d821 2022-06-25 stsp goto done;
1254 c7d5c43c 2022-08-04 mark err = show_object_id(lines, nlines, "tree", '+', idstr, outfile);
1256 8469d821 2022-06-25 stsp goto done;
1257 8469d821 2022-06-25 stsp free(idstr);
1258 8469d821 2022-06-25 stsp idstr = NULL;
1260 c7d5c43c 2022-08-04 mark err = show_object_id(lines, nlines, "tree", '+', "/dev/null",
1263 8469d821 2022-06-25 stsp goto done;
1266 c7d5c43c 2022-08-04 mark err = diff_objects_as_trees(lines, nlines, f1, f2, fd1, fd2, id1, id2,
1267 c7d5c43c 2022-08-04 mark paths, label1, label2, diff_context, ignore_whitespace,
1268 a76e88e5 2023-01-10 mark force_text_diff, show_diffstat, dsa, repo, outfile, diff_algo);
1270 8469d821 2022-06-25 stsp free(idstr);
1271 8469d821 2022-06-25 stsp return err;
1274 8469d821 2022-06-25 stsp const struct got_error *
1275 c7d5c43c 2022-08-04 mark got_diff_objects_as_commits(struct got_diff_line **lines, size_t *nlines,
1276 f9d37699 2022-06-28 stsp FILE *f1, FILE *f2, int fd1, int fd2,
1277 f9d37699 2022-06-28 stsp struct got_object_id *id1, struct got_object_id *id2,
1278 4b752015 2022-06-30 stsp struct got_pathlist_head *paths, enum got_diff_algorithm diff_algo,
1279 64453f7e 2020-11-21 stsp int diff_context, int ignore_whitespace, int force_text_diff,
1280 a76e88e5 2023-01-10 mark int show_diffstat, struct got_diffstat_cb_arg *dsa,
1281 15a94983 2018-12-23 stsp struct got_repository *repo, FILE *outfile)
1283 11528a82 2018-05-19 stsp const struct got_error *err;
1284 11528a82 2018-05-19 stsp struct got_commit_object *commit1 = NULL, *commit2 = NULL;
1285 8469d821 2022-06-25 stsp char *idstr = NULL;
1287 15a94983 2018-12-23 stsp if (id2 == NULL)
1288 b74c7625 2018-05-20 stsp return got_error(GOT_ERR_NO_OBJ);
1290 15a94983 2018-12-23 stsp if (id1) {
1291 15a94983 2018-12-23 stsp err = got_object_open_as_commit(&commit1, repo, id1);
1293 cd0acaa7 2018-05-20 stsp goto done;
1294 8469d821 2022-06-25 stsp err = got_object_id_str(&idstr, id1);
1296 8469d821 2022-06-25 stsp goto done;
1297 c7d5c43c 2022-08-04 mark err = show_object_id(lines, nlines, "commit", '-', idstr,
1300 8469d821 2022-06-25 stsp goto done;
1301 8469d821 2022-06-25 stsp free(idstr);
1302 8469d821 2022-06-25 stsp idstr = NULL;
1304 c7d5c43c 2022-08-04 mark err = show_object_id(lines, nlines, "commit", '-', "/dev/null",
1307 8469d821 2022-06-25 stsp goto done;
1310 15a94983 2018-12-23 stsp err = got_object_open_as_commit(&commit2, repo, id2);
1312 9b697879 2018-05-20 stsp goto done;
1314 8469d821 2022-06-25 stsp err = got_object_id_str(&idstr, id2);
1316 8469d821 2022-06-25 stsp goto done;
1317 c7d5c43c 2022-08-04 mark err = show_object_id(lines, nlines, "commit", '+', idstr, outfile);
1319 8469d821 2022-06-25 stsp goto done;
1321 c7d5c43c 2022-08-04 mark err = diff_objects_as_trees(lines, nlines, f1, f2, fd1, fd2,
1322 15a94983 2018-12-23 stsp commit1 ? got_object_commit_get_tree_id(commit1) : NULL,
1323 67b631c9 2021-10-10 stsp got_object_commit_get_tree_id(commit2), paths, "", "",
1324 a76e88e5 2023-01-10 mark diff_context, ignore_whitespace, force_text_diff, show_diffstat,
1325 a76e88e5 2023-01-10 mark dsa, repo, outfile, diff_algo);
1327 11528a82 2018-05-19 stsp if (commit1)
1328 11528a82 2018-05-19 stsp got_object_commit_close(commit1);
1329 11528a82 2018-05-19 stsp if (commit2)
1330 11528a82 2018-05-19 stsp got_object_commit_close(commit2);
1331 8469d821 2022-06-25 stsp free(idstr);
1332 11528a82 2018-05-19 stsp return err;
1335 dc424a06 2019-08-07 stsp const struct got_error *
1336 fe621944 2020-11-10 stsp got_diff_files(struct got_diffreg_result **resultp,
1337 49d4a017 2022-06-30 stsp FILE *f1, int f1_exists, const char *label1, FILE *f2, int f2_exists,
1338 49d4a017 2022-06-30 stsp const char *label2, int diff_context, int ignore_whitespace,
1339 4b752015 2022-06-30 stsp int force_text_diff, FILE *outfile, enum got_diff_algorithm diff_algo)
1341 dc424a06 2019-08-07 stsp const struct got_error *err = NULL;
1342 fe621944 2020-11-10 stsp struct got_diffreg_result *diffreg_result = NULL;
1344 fe621944 2020-11-10 stsp if (resultp)
1345 fe621944 2020-11-10 stsp *resultp = NULL;
1347 dc424a06 2019-08-07 stsp if (outfile) {
1348 dc424a06 2019-08-07 stsp fprintf(outfile, "file - %s\n",
1349 49d4a017 2022-06-30 stsp f1_exists ? label1 : "/dev/null");
1350 dc424a06 2019-08-07 stsp fprintf(outfile, "file + %s\n",
1351 49d4a017 2022-06-30 stsp f2_exists ? label2 : "/dev/null");
1354 4b752015 2022-06-30 stsp err = got_diffreg(&diffreg_result, f1, f2, diff_algo,
1355 64453f7e 2020-11-21 stsp ignore_whitespace, force_text_diff);
1357 fe621944 2020-11-10 stsp goto done;
1359 fe621944 2020-11-10 stsp if (outfile) {
1360 fe621944 2020-11-10 stsp err = got_diffreg_output(NULL, NULL, diffreg_result,
1361 49d4a017 2022-06-30 stsp f1_exists, f2_exists, label1, label2,
1362 1cb46f00 2020-11-21 stsp GOT_DIFF_OUTPUT_UNIDIFF, diff_context, outfile);
1364 dc424a06 2019-08-07 stsp goto done;
1368 fe621944 2020-11-10 stsp if (resultp && err == NULL)
1369 fe621944 2020-11-10 stsp *resultp = diffreg_result;
1370 fe621944 2020-11-10 stsp else if (diffreg_result) {
1371 fe621944 2020-11-10 stsp const struct got_error *free_err;
1372 fe621944 2020-11-10 stsp free_err = got_diffreg_result_free(diffreg_result);
1373 fe621944 2020-11-10 stsp if (free_err && err == NULL)
1374 fe621944 2020-11-10 stsp err = free_err;
1377 dc424a06 2019-08-07 stsp return err;