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 511a516b 2018-05-19 stsp #include "got_opentemp.h"
32 324d37e7 2019-05-11 stsp #include "got_path.h"
33 0208f208 2020-05-05 stsp #include "got_cancel.h"
34 0208f208 2020-05-05 stsp #include "got_worktree.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"
41 404c43c4 2018-06-21 stsp static const struct got_error *
42 404c43c4 2018-06-21 stsp diff_blobs(struct got_blob_object *blob1, struct got_blob_object *blob2,
43 46f68b20 2019-10-19 stsp const char *label1, const char *label2, mode_t mode1, mode_t mode2,
44 46f68b20 2019-10-19 stsp int diff_context, int ignore_whitespace, FILE *outfile,
45 46f68b20 2019-10-19 stsp struct got_diff_changes *changes)
47 ed9e98a8 2017-11-29 stsp struct got_diff_state ds;
48 8ba9a219 2017-11-29 stsp struct got_diff_args args;
49 7d283eee 2017-11-29 stsp const struct got_error *err = NULL;
50 4e22badc 2017-11-30 stsp FILE *f1 = NULL, *f2 = NULL;
51 f78b0693 2017-11-29 stsp char hex1[SHA1_DIGEST_STRING_LENGTH];
52 f78b0693 2017-11-29 stsp char hex2[SHA1_DIGEST_STRING_LENGTH];
53 98abbc84 2017-11-30 stsp char *idstr1 = NULL, *idstr2 = NULL;
54 f934cf2c 2018-02-12 stsp size_t size1, size2;
55 4e22badc 2017-11-30 stsp int res, flags = 0;
57 4e22badc 2017-11-30 stsp if (blob1) {
58 a1fd68d8 2018-01-12 stsp f1 = got_opentemp();
59 4e22badc 2017-11-30 stsp if (f1 == NULL)
60 638f9024 2019-05-13 stsp return got_error_from_errno("got_opentemp");
62 4e22badc 2017-11-30 stsp flags |= D_EMPTY1;
64 4e22badc 2017-11-30 stsp if (blob2) {
65 a1fd68d8 2018-01-12 stsp f2 = got_opentemp();
66 4e22badc 2017-11-30 stsp if (f2 == NULL) {
67 638f9024 2019-05-13 stsp err = got_error_from_errno("got_opentemp");
72 4e22badc 2017-11-30 stsp flags |= D_EMPTY2;
75 98abbc84 2017-11-30 stsp if (blob1) {
76 f934cf2c 2018-02-12 stsp idstr1 = got_object_blob_id_str(blob1, hex1, sizeof(hex1));
77 6c4c42e0 2019-06-24 stsp err = got_object_blob_dump_to_file(&size1, NULL, NULL, f1,
82 98abbc84 2017-11-30 stsp idstr1 = "/dev/null";
85 98abbc84 2017-11-30 stsp if (blob2) {
86 f934cf2c 2018-02-12 stsp idstr2 = got_object_blob_id_str(blob2, hex2, sizeof(hex2));
87 6c4c42e0 2019-06-24 stsp err = got_object_blob_dump_to_file(&size2, NULL, NULL, f2,
92 98abbc84 2017-11-30 stsp idstr2 = "/dev/null";
94 ed9e98a8 2017-11-29 stsp memset(&ds, 0, sizeof(ds));
95 f9d67749 2017-11-30 stsp /* XXX should stat buffers be passed in args instead of ds? */
96 f9d67749 2017-11-30 stsp ds.stb1.st_mode = S_IFREG;
98 f934cf2c 2018-02-12 stsp ds.stb1.st_size = size1;
99 f9d67749 2017-11-30 stsp ds.stb1.st_mtime = 0; /* XXX */
101 f9d67749 2017-11-30 stsp ds.stb2.st_mode = S_IFREG;
103 f934cf2c 2018-02-12 stsp ds.stb2.st_size = size2;
104 f9d67749 2017-11-30 stsp ds.stb2.st_mtime = 0; /* XXX */
106 54156555 2018-12-24 stsp memset(&args, 0, sizeof(args));
107 8ba9a219 2017-11-29 stsp args.diff_format = D_UNIFIED;
108 54156555 2018-12-24 stsp args.label[0] = label1 ? label1 : idstr1;
109 54156555 2018-12-24 stsp args.label[1] = label2 ? label2 : idstr2;
110 df2871d2 2018-10-18 stsp args.diff_context = diff_context;
111 84eb021e 2018-03-27 stsp flags |= D_PROTOTYPE;
112 63035f9f 2019-10-06 stsp if (ignore_whitespace)
113 63035f9f 2019-10-06 stsp flags |= D_IGNOREBLANKS;
115 09de383e 2018-12-24 stsp if (outfile) {
116 46f68b20 2019-10-19 stsp char *modestr1 = NULL, *modestr2 = NULL;
117 40dde666 2020-07-23 stsp int modebits;
118 46f68b20 2019-10-19 stsp if (mode1 && mode1 != mode2) {
119 40dde666 2020-07-23 stsp if (S_ISLNK(mode1))
120 40dde666 2020-07-23 stsp modebits = S_IFLNK;
122 40dde666 2020-07-23 stsp modebits = (S_IRWXU | S_IRWXG | S_IRWXO);
123 46f68b20 2019-10-19 stsp if (asprintf(&modestr1, " (mode %o)",
124 40dde666 2020-07-23 stsp mode1 & modebits) == -1) {
125 46f68b20 2019-10-19 stsp err = got_error_from_errno("asprintf");
129 46f68b20 2019-10-19 stsp if (mode2 && mode1 != mode2) {
130 40dde666 2020-07-23 stsp if (S_ISLNK(mode2))
131 40dde666 2020-07-23 stsp modebits = S_IFLNK;
133 40dde666 2020-07-23 stsp modebits = (S_IRWXU | S_IRWXG | S_IRWXO);
134 46f68b20 2019-10-19 stsp if (asprintf(&modestr2, " (mode %o)",
135 40dde666 2020-07-23 stsp mode2 & modebits) == -1) {
136 46f68b20 2019-10-19 stsp err = got_error_from_errno("asprintf");
140 46f68b20 2019-10-19 stsp fprintf(outfile, "blob - %s%s\n", idstr1,
141 46f68b20 2019-10-19 stsp modestr1 ? modestr1 : "");
142 46f68b20 2019-10-19 stsp fprintf(outfile, "blob + %s%s\n", idstr2,
143 46f68b20 2019-10-19 stsp modestr2 ? modestr2 : "");
144 46f68b20 2019-10-19 stsp free(modestr1);
145 46f68b20 2019-10-19 stsp free(modestr2);
147 404c43c4 2018-06-21 stsp err = got_diffreg(&res, f1, f2, flags, &args, &ds, outfile, changes);
148 dc424a06 2019-08-07 stsp got_diff_state_free(&ds);
150 fb43ecf1 2019-02-11 stsp if (f1 && fclose(f1) != 0 && err == NULL)
151 638f9024 2019-05-13 stsp err = got_error_from_errno("fclose");
152 fb43ecf1 2019-02-11 stsp if (f2 && fclose(f2) != 0 && err == NULL)
153 638f9024 2019-05-13 stsp err = got_error_from_errno("fclose");
154 7d283eee 2017-11-29 stsp return err;
157 aaa13589 2019-06-01 stsp const struct got_error *
158 aaa13589 2019-06-01 stsp got_diff_blob_output_unidiff(void *arg, struct got_blob_object *blob1,
159 aaa13589 2019-06-01 stsp struct got_blob_object *blob2, struct got_object_id *id1,
160 aaa13589 2019-06-01 stsp struct got_object_id *id2, const char *label1, const char *label2,
161 46f68b20 2019-10-19 stsp mode_t mode1, mode_t mode2, struct got_repository *repo)
163 aaa13589 2019-06-01 stsp struct got_diff_blob_output_unidiff_arg *a = arg;
165 46f68b20 2019-10-19 stsp return diff_blobs(blob1, blob2, label1, label2, mode1, mode2,
166 46f68b20 2019-10-19 stsp a->diff_context, a->ignore_whitespace, a->outfile, NULL);
169 404c43c4 2018-06-21 stsp const struct got_error *
170 404c43c4 2018-06-21 stsp got_diff_blob(struct got_blob_object *blob1, struct got_blob_object *blob2,
171 63035f9f 2019-10-06 stsp const char *label1, const char *label2, int diff_context,
172 63035f9f 2019-10-06 stsp int ignore_whitespace, FILE *outfile)
174 46f68b20 2019-10-19 stsp return diff_blobs(blob1, blob2, label1, label2, 0, 0, diff_context,
175 63035f9f 2019-10-06 stsp ignore_whitespace, outfile, NULL);
178 7f1f93af 2019-08-06 stsp static const struct got_error *
179 7f1f93af 2019-08-06 stsp alloc_changes(struct got_diff_changes **changes)
181 7f1f93af 2019-08-06 stsp *changes = calloc(1, sizeof(**changes));
182 7f1f93af 2019-08-06 stsp if (*changes == NULL)
183 7f1f93af 2019-08-06 stsp return got_error_from_errno("calloc");
184 7f1f93af 2019-08-06 stsp SIMPLEQ_INIT(&(*changes)->entries);
185 7f1f93af 2019-08-06 stsp return NULL;
188 7f1f93af 2019-08-06 stsp static const struct got_error *
189 7f1f93af 2019-08-06 stsp diff_blob_file(struct got_diff_changes **changes,
190 4ce46740 2019-08-08 stsp struct got_blob_object *blob1, const char *label1, FILE *f2, size_t size2,
191 63035f9f 2019-10-06 stsp const char *label2, int diff_context, int ignore_whitespace, FILE *outfile)
193 b72f483a 2019-02-05 stsp struct got_diff_state ds;
194 b72f483a 2019-02-05 stsp struct got_diff_args args;
195 b72f483a 2019-02-05 stsp const struct got_error *err = NULL;
196 b72f483a 2019-02-05 stsp FILE *f1 = NULL;
197 b72f483a 2019-02-05 stsp char hex1[SHA1_DIGEST_STRING_LENGTH];
198 b72f483a 2019-02-05 stsp char *idstr1 = NULL;
199 b72f483a 2019-02-05 stsp size_t size1;
200 b72f483a 2019-02-05 stsp int res, flags = 0;
202 7f1f93af 2019-08-06 stsp if (changes)
203 7f1f93af 2019-08-06 stsp *changes = NULL;
206 b72f483a 2019-02-05 stsp if (blob1) {
207 b72f483a 2019-02-05 stsp f1 = got_opentemp();
208 b72f483a 2019-02-05 stsp if (f1 == NULL)
209 638f9024 2019-05-13 stsp return got_error_from_errno("got_opentemp");
210 b72f483a 2019-02-05 stsp idstr1 = got_object_blob_id_str(blob1, hex1, sizeof(hex1));
211 6c4c42e0 2019-06-24 stsp err = got_object_blob_dump_to_file(&size1, NULL, NULL, f1,
216 b72f483a 2019-02-05 stsp flags |= D_EMPTY1;
217 b72f483a 2019-02-05 stsp idstr1 = "/dev/null";
220 b72f483a 2019-02-05 stsp if (f2 == NULL)
221 b72f483a 2019-02-05 stsp flags |= D_EMPTY2;
223 b72f483a 2019-02-05 stsp memset(&ds, 0, sizeof(ds));
224 b72f483a 2019-02-05 stsp /* XXX should stat buffers be passed in args instead of ds? */
225 b72f483a 2019-02-05 stsp ds.stb1.st_mode = S_IFREG;
227 b72f483a 2019-02-05 stsp ds.stb1.st_size = size1;
228 b72f483a 2019-02-05 stsp ds.stb1.st_mtime = 0; /* XXX */
230 b72f483a 2019-02-05 stsp ds.stb2.st_mode = S_IFREG;
231 b72f483a 2019-02-05 stsp ds.stb2.st_size = size2;
232 b72f483a 2019-02-05 stsp ds.stb2.st_mtime = 0; /* XXX */
234 b72f483a 2019-02-05 stsp memset(&args, 0, sizeof(args));
235 b72f483a 2019-02-05 stsp args.diff_format = D_UNIFIED;
236 b72f483a 2019-02-05 stsp args.label[0] = label2;
237 b72f483a 2019-02-05 stsp args.label[1] = label2;
238 b72f483a 2019-02-05 stsp args.diff_context = diff_context;
239 b72f483a 2019-02-05 stsp flags |= D_PROTOTYPE;
240 63035f9f 2019-10-06 stsp if (ignore_whitespace)
241 63035f9f 2019-10-06 stsp flags |= D_IGNOREBLANKS;
243 7f1f93af 2019-08-06 stsp if (outfile) {
244 4ce46740 2019-08-08 stsp fprintf(outfile, "blob - %s\n", label1 ? label1 : idstr1);
245 7f1f93af 2019-08-06 stsp fprintf(outfile, "file + %s\n",
246 7f1f93af 2019-08-06 stsp f2 == NULL ? "/dev/null" : label2);
248 7f1f93af 2019-08-06 stsp if (changes) {
249 7f1f93af 2019-08-06 stsp err = alloc_changes(changes);
251 7f1f93af 2019-08-06 stsp return err;
253 7f1f93af 2019-08-06 stsp err = got_diffreg(&res, f1, f2, flags, &args, &ds, outfile,
254 7f1f93af 2019-08-06 stsp changes ? *changes : NULL);
255 dc424a06 2019-08-07 stsp got_diff_state_free(&ds);
257 fb43ecf1 2019-02-11 stsp if (f1 && fclose(f1) != 0 && err == NULL)
258 638f9024 2019-05-13 stsp err = got_error_from_errno("fclose");
259 b72f483a 2019-02-05 stsp return err;
262 7f1f93af 2019-08-06 stsp const struct got_error *
263 4ce46740 2019-08-08 stsp got_diff_blob_file(struct got_blob_object *blob1, const char *label1,
264 4ce46740 2019-08-08 stsp FILE *f2, size_t size2, const char *label2, int diff_context,
265 63035f9f 2019-10-06 stsp int ignore_whitespace, FILE *outfile)
267 4ce46740 2019-08-08 stsp return diff_blob_file(NULL, blob1, label1, f2, size2, label2,
268 63035f9f 2019-10-06 stsp diff_context, ignore_whitespace, outfile);
271 4c9641fd 2019-08-21 stsp const struct got_error *
272 4c9641fd 2019-08-21 stsp got_diff_blob_file_lines_changed(struct got_diff_changes **changes,
273 4c9641fd 2019-08-21 stsp struct got_blob_object *blob1, FILE *f2, size_t size2)
275 4c9641fd 2019-08-21 stsp return diff_blob_file(changes, blob1, NULL, f2, size2, NULL,
276 63035f9f 2019-10-06 stsp 0, 0, NULL);
279 7f1f93af 2019-08-06 stsp const struct got_error *
280 404c43c4 2018-06-21 stsp got_diff_blob_lines_changed(struct got_diff_changes **changes,
281 404c43c4 2018-06-21 stsp struct got_blob_object *blob1, struct got_blob_object *blob2)
283 404c43c4 2018-06-21 stsp const struct got_error *err = NULL;
285 7f1f93af 2019-08-06 stsp err = alloc_changes(changes);
287 7f1f93af 2019-08-06 stsp return err;
289 46f68b20 2019-10-19 stsp err = diff_blobs(blob1, blob2, NULL, NULL, 0, 0, 3, 0, NULL, *changes);
291 404c43c4 2018-06-21 stsp got_diff_free_changes(*changes);
292 404c43c4 2018-06-21 stsp *changes = NULL;
294 404c43c4 2018-06-21 stsp return err;
298 404c43c4 2018-06-21 stsp got_diff_free_changes(struct got_diff_changes *changes)
300 404c43c4 2018-06-21 stsp struct got_diff_change *change;
301 404c43c4 2018-06-21 stsp while (!SIMPLEQ_EMPTY(&changes->entries)) {
302 404c43c4 2018-06-21 stsp change = SIMPLEQ_FIRST(&changes->entries);
303 404c43c4 2018-06-21 stsp SIMPLEQ_REMOVE_HEAD(&changes->entries, entry);
304 404c43c4 2018-06-21 stsp free(change);
306 404c43c4 2018-06-21 stsp free(changes);
309 474b4f94 2017-11-30 stsp static const struct got_error *
310 46f68b20 2019-10-19 stsp diff_added_blob(struct got_object_id *id, const char *label, mode_t mode,
311 aaa13589 2019-06-01 stsp struct got_repository *repo, got_diff_blob_cb cb, void *cb_arg)
313 4e22badc 2017-11-30 stsp const struct got_error *err;
314 2acfca77 2018-04-01 stsp struct got_blob_object *blob = NULL;
315 2acfca77 2018-04-01 stsp struct got_object *obj = NULL;
317 4e22badc 2017-11-30 stsp err = got_object_open(&obj, repo, id);
319 4e22badc 2017-11-30 stsp return err;
321 2acfca77 2018-04-01 stsp err = got_object_blob_open(&blob, repo, obj, 8192);
324 46f68b20 2019-10-19 stsp err = cb(cb_arg, NULL, blob, NULL, id, NULL, label, 0, mode, repo);
326 2acfca77 2018-04-01 stsp got_object_close(obj);
328 2acfca77 2018-04-01 stsp got_object_blob_close(blob);
329 2acfca77 2018-04-01 stsp return err;
332 474b4f94 2017-11-30 stsp static const struct got_error *
333 6a213ccb 2017-11-30 stsp diff_modified_blob(struct got_object_id *id1, struct got_object_id *id2,
334 46f68b20 2019-10-19 stsp const char *label1, const char *label2, mode_t mode1, mode_t mode2,
335 46f68b20 2019-10-19 stsp struct got_repository *repo, got_diff_blob_cb cb, void *cb_arg)
337 6a213ccb 2017-11-30 stsp const struct got_error *err;
338 6a213ccb 2017-11-30 stsp struct got_object *obj1 = NULL;
339 6a213ccb 2017-11-30 stsp struct got_object *obj2 = NULL;
340 6a213ccb 2017-11-30 stsp struct got_blob_object *blob1 = NULL;
341 6a213ccb 2017-11-30 stsp struct got_blob_object *blob2 = NULL;
343 6a213ccb 2017-11-30 stsp err = got_object_open(&obj1, repo, id1);
345 730a8aa0 2018-04-24 stsp return err;
346 15a94983 2018-12-23 stsp if (obj1->type != GOT_OBJ_TYPE_BLOB) {
347 6a213ccb 2017-11-30 stsp err = got_error(GOT_ERR_OBJ_TYPE);
351 6a213ccb 2017-11-30 stsp err = got_object_open(&obj2, repo, id2);
354 15a94983 2018-12-23 stsp if (obj2->type != GOT_OBJ_TYPE_BLOB) {
355 6a213ccb 2017-11-30 stsp err = got_error(GOT_ERR_BAD_OBJ_DATA);
359 c7020aea 2017-11-30 stsp err = got_object_blob_open(&blob1, repo, obj1, 8192);
363 c7020aea 2017-11-30 stsp err = got_object_blob_open(&blob2, repo, obj2, 8192);
367 46f68b20 2019-10-19 stsp err = cb(cb_arg, blob1, blob2, id1, id2, label1, label2, mode1, mode2,
371 a3e2cbea 2017-12-01 stsp got_object_close(obj1);
373 a3e2cbea 2017-12-01 stsp got_object_close(obj2);
375 a3e2cbea 2017-12-01 stsp got_object_blob_close(blob1);
377 a3e2cbea 2017-12-01 stsp got_object_blob_close(blob2);
378 6a213ccb 2017-11-30 stsp return err;
381 474b4f94 2017-11-30 stsp static const struct got_error *
382 46f68b20 2019-10-19 stsp diff_deleted_blob(struct got_object_id *id, const char *label, mode_t mode,
383 aaa13589 2019-06-01 stsp struct got_repository *repo, got_diff_blob_cb cb, void *cb_arg)
385 365fb436 2017-11-30 stsp const struct got_error *err;
386 2acfca77 2018-04-01 stsp struct got_blob_object *blob = NULL;
387 2acfca77 2018-04-01 stsp struct got_object *obj = NULL;
389 365fb436 2017-11-30 stsp err = got_object_open(&obj, repo, id);
391 365fb436 2017-11-30 stsp return err;
393 2acfca77 2018-04-01 stsp err = got_object_blob_open(&blob, repo, obj, 8192);
396 46f68b20 2019-10-19 stsp err = cb(cb_arg, blob, NULL, id, NULL, label, NULL, mode, 0, repo);
398 2acfca77 2018-04-01 stsp got_object_close(obj);
400 2acfca77 2018-04-01 stsp got_object_blob_close(blob);
401 2acfca77 2018-04-01 stsp return err;
404 474b4f94 2017-11-30 stsp static const struct got_error *
405 54156555 2018-12-24 stsp diff_added_tree(struct got_object_id *id, const char *label,
406 31b4484f 2019-07-27 stsp struct got_repository *repo, got_diff_blob_cb cb, void *cb_arg,
407 31b4484f 2019-07-27 stsp int diff_content)
409 9c70d4c3 2017-11-30 stsp const struct got_error *err = NULL;
410 9c70d4c3 2017-11-30 stsp struct got_object *treeobj = NULL;
411 9c70d4c3 2017-11-30 stsp struct got_tree_object *tree = NULL;
413 9c70d4c3 2017-11-30 stsp err = got_object_open(&treeobj, repo, id);
417 15a94983 2018-12-23 stsp if (treeobj->type != GOT_OBJ_TYPE_TREE) {
418 9c70d4c3 2017-11-30 stsp err = got_error(GOT_ERR_OBJ_TYPE);
422 9c70d4c3 2017-11-30 stsp err = got_object_tree_open(&tree, repo, treeobj);
426 31b4484f 2019-07-27 stsp err = got_diff_tree(NULL, tree, NULL, label, repo, cb, cb_arg,
427 31b4484f 2019-07-27 stsp diff_content);
430 9c70d4c3 2017-11-30 stsp got_object_tree_close(tree);
431 9c70d4c3 2017-11-30 stsp if (treeobj)
432 9c70d4c3 2017-11-30 stsp got_object_close(treeobj);
433 9c70d4c3 2017-11-30 stsp return err;
436 474b4f94 2017-11-30 stsp static const struct got_error *
437 789689b5 2017-11-30 stsp diff_modified_tree(struct got_object_id *id1, struct got_object_id *id2,
438 aaa13589 2019-06-01 stsp const char *label1, const char *label2, struct got_repository *repo,
439 31b4484f 2019-07-27 stsp got_diff_blob_cb cb, void *cb_arg, int diff_content)
441 f6861a81 2018-09-13 stsp const struct got_error *err;
442 789689b5 2017-11-30 stsp struct got_object *treeobj1 = NULL;
443 789689b5 2017-11-30 stsp struct got_object *treeobj2 = NULL;
444 789689b5 2017-11-30 stsp struct got_tree_object *tree1 = NULL;
445 789689b5 2017-11-30 stsp struct got_tree_object *tree2 = NULL;
447 789689b5 2017-11-30 stsp err = got_object_open(&treeobj1, repo, id1);
451 15a94983 2018-12-23 stsp if (treeobj1->type != GOT_OBJ_TYPE_TREE) {
452 789689b5 2017-11-30 stsp err = got_error(GOT_ERR_OBJ_TYPE);
456 789689b5 2017-11-30 stsp err = got_object_open(&treeobj2, repo, id2);
460 15a94983 2018-12-23 stsp if (treeobj2->type != GOT_OBJ_TYPE_TREE) {
461 789689b5 2017-11-30 stsp err = got_error(GOT_ERR_OBJ_TYPE);
465 789689b5 2017-11-30 stsp err = got_object_tree_open(&tree1, repo, treeobj1);
469 789689b5 2017-11-30 stsp err = got_object_tree_open(&tree2, repo, treeobj2);
473 31b4484f 2019-07-27 stsp err = got_diff_tree(tree1, tree2, label1, label2, repo, cb, cb_arg,
474 31b4484f 2019-07-27 stsp diff_content);
478 789689b5 2017-11-30 stsp got_object_tree_close(tree1);
480 789689b5 2017-11-30 stsp got_object_tree_close(tree2);
481 789689b5 2017-11-30 stsp if (treeobj1)
482 789689b5 2017-11-30 stsp got_object_close(treeobj1);
483 789689b5 2017-11-30 stsp if (treeobj2)
484 789689b5 2017-11-30 stsp got_object_close(treeobj2);
485 789689b5 2017-11-30 stsp return err;
488 474b4f94 2017-11-30 stsp static const struct got_error *
489 54156555 2018-12-24 stsp diff_deleted_tree(struct got_object_id *id, const char *label,
490 31b4484f 2019-07-27 stsp struct got_repository *repo, got_diff_blob_cb cb, void *cb_arg,
491 31b4484f 2019-07-27 stsp int diff_content)
493 f6861a81 2018-09-13 stsp const struct got_error *err;
494 2c56f2ce 2017-11-30 stsp struct got_object *treeobj = NULL;
495 2c56f2ce 2017-11-30 stsp struct got_tree_object *tree = NULL;
497 2c56f2ce 2017-11-30 stsp err = got_object_open(&treeobj, repo, id);
501 15a94983 2018-12-23 stsp if (treeobj->type != GOT_OBJ_TYPE_TREE) {
502 2c56f2ce 2017-11-30 stsp err = got_error(GOT_ERR_OBJ_TYPE);
506 2c56f2ce 2017-11-30 stsp err = got_object_tree_open(&tree, repo, treeobj);
510 31b4484f 2019-07-27 stsp err = got_diff_tree(tree, NULL, label, NULL, repo, cb, cb_arg,
511 31b4484f 2019-07-27 stsp diff_content);
514 2c56f2ce 2017-11-30 stsp got_object_tree_close(tree);
515 2c56f2ce 2017-11-30 stsp if (treeobj)
516 2c56f2ce 2017-11-30 stsp got_object_close(treeobj);
517 2c56f2ce 2017-11-30 stsp return err;
520 474b4f94 2017-11-30 stsp static const struct got_error *
521 74671950 2018-02-11 stsp diff_kind_mismatch(struct got_object_id *id1, struct got_object_id *id2,
522 aaa13589 2019-06-01 stsp const char *label1, const char *label2, struct got_repository *repo,
523 aaa13589 2019-06-01 stsp got_diff_blob_cb cb, void *cb_arg)
525 013404a9 2017-11-30 stsp /* XXX TODO */
526 474b4f94 2017-11-30 stsp return NULL;
529 474b4f94 2017-11-30 stsp static const struct got_error *
530 56e0773d 2019-11-28 stsp diff_entry_old_new(struct got_tree_entry *te1,
531 56e0773d 2019-11-28 stsp struct got_tree_entry *te2, const char *label1, const char *label2,
532 31b4484f 2019-07-27 stsp struct got_repository *repo, got_diff_blob_cb cb, void *cb_arg,
533 31b4484f 2019-07-27 stsp int diff_content)
535 f6861a81 2018-09-13 stsp const struct got_error *err = NULL;
536 19ae6da1 2018-11-05 stsp int id_match;
538 63c5ca5d 2019-08-24 stsp if (got_object_tree_entry_is_submodule(te1))
539 63c5ca5d 2019-08-24 stsp return NULL;
541 474b4f94 2017-11-30 stsp if (te2 == NULL) {
542 474b4f94 2017-11-30 stsp if (S_ISDIR(te1->mode))
543 56e0773d 2019-11-28 stsp err = diff_deleted_tree(&te1->id, label1, repo,
544 31b4484f 2019-07-27 stsp cb, cb_arg, diff_content);
546 31b4484f 2019-07-27 stsp if (diff_content)
547 56e0773d 2019-11-28 stsp err = diff_deleted_blob(&te1->id, label1,
548 46f68b20 2019-10-19 stsp te1->mode, repo, cb, cb_arg);
550 56e0773d 2019-11-28 stsp err = cb(cb_arg, NULL, NULL, &te1->id, NULL,
551 46f68b20 2019-10-19 stsp label1, NULL, te1->mode, 0, repo);
553 f6861a81 2018-09-13 stsp return err;
554 63c5ca5d 2019-08-24 stsp } else if (got_object_tree_entry_is_submodule(te2))
555 63c5ca5d 2019-08-24 stsp return NULL;
557 56e0773d 2019-11-28 stsp id_match = (got_object_id_cmp(&te1->id, &te2->id) == 0);
558 4209f790 2017-11-30 stsp if (S_ISDIR(te1->mode) && S_ISDIR(te2->mode)) {
559 19ae6da1 2018-11-05 stsp if (!id_match)
560 56e0773d 2019-11-28 stsp return diff_modified_tree(&te1->id, &te2->id,
561 31b4484f 2019-07-27 stsp label1, label2, repo, cb, cb_arg, diff_content);
562 40dde666 2020-07-23 stsp } else if ((S_ISREG(te1->mode) || S_ISLNK(te1->mode)) &&
563 40dde666 2020-07-23 stsp (S_ISREG(te2->mode) || S_ISLNK(te2->mode))) {
564 46f68b20 2019-10-19 stsp if (!id_match ||
565 40dde666 2020-07-23 stsp ((te1->mode & (S_IFLNK | S_IXUSR))) !=
566 40dde666 2020-07-23 stsp (te2->mode & (S_IFLNK | S_IXUSR))) {
567 31b4484f 2019-07-27 stsp if (diff_content)
568 56e0773d 2019-11-28 stsp return diff_modified_blob(&te1->id, &te2->id,
569 46f68b20 2019-10-19 stsp label1, label2, te1->mode, te2->mode,
570 46f68b20 2019-10-19 stsp repo, cb, cb_arg);
572 56e0773d 2019-11-28 stsp return cb(cb_arg, NULL, NULL, &te1->id,
573 56e0773d 2019-11-28 stsp &te2->id, label1, label2, te1->mode,
574 46f68b20 2019-10-19 stsp te2->mode, repo);
578 19ae6da1 2018-11-05 stsp if (id_match)
579 f6861a81 2018-09-13 stsp return NULL;
581 56e0773d 2019-11-28 stsp return diff_kind_mismatch(&te1->id, &te2->id, label1, label2, repo,
582 aaa13589 2019-06-01 stsp cb, cb_arg);
585 474b4f94 2017-11-30 stsp static const struct got_error *
586 56e0773d 2019-11-28 stsp diff_entry_new_old(struct got_tree_entry *te2,
587 56e0773d 2019-11-28 stsp struct got_tree_entry *te1, const char *label2,
588 31b4484f 2019-07-27 stsp struct got_repository *repo, got_diff_blob_cb cb, void *cb_arg,
589 31b4484f 2019-07-27 stsp int diff_content)
591 f6861a81 2018-09-13 stsp if (te1 != NULL) /* handled by diff_entry_old_new() */
592 63c5ca5d 2019-08-24 stsp return NULL;
594 63c5ca5d 2019-08-24 stsp if (got_object_tree_entry_is_submodule(te2))
595 f6861a81 2018-09-13 stsp return NULL;
597 474b4f94 2017-11-30 stsp if (S_ISDIR(te2->mode))
598 56e0773d 2019-11-28 stsp return diff_added_tree(&te2->id, label2, repo, cb, cb_arg,
599 31b4484f 2019-07-27 stsp diff_content);
601 31b4484f 2019-07-27 stsp if (diff_content)
602 56e0773d 2019-11-28 stsp return diff_added_blob(&te2->id, label2, te2->mode, repo, cb,
605 56e0773d 2019-11-28 stsp return cb(cb_arg, NULL, NULL, NULL, &te2->id, NULL, label2, 0,
606 46f68b20 2019-10-19 stsp te2->mode, repo);
609 0208f208 2020-05-05 stsp const struct got_error *
610 0208f208 2020-05-05 stsp got_diff_tree_collect_changed_paths(void *arg, struct got_blob_object *blob1,
611 0208f208 2020-05-05 stsp struct got_blob_object *blob2, struct got_object_id *id1,
612 0208f208 2020-05-05 stsp struct got_object_id *id2, const char *label1, const char *label2,
613 0208f208 2020-05-05 stsp mode_t mode1, mode_t mode2, struct got_repository *repo)
615 0208f208 2020-05-05 stsp const struct got_error *err = NULL;
616 0208f208 2020-05-05 stsp struct got_pathlist_head *paths = arg;
617 0208f208 2020-05-05 stsp struct got_diff_changed_path *change = NULL;
618 0208f208 2020-05-05 stsp char *path = NULL;
620 0208f208 2020-05-05 stsp path = strdup(label2 ? label2 : label1);
621 0208f208 2020-05-05 stsp if (path == NULL)
622 0208f208 2020-05-05 stsp return got_error_from_errno("malloc");
624 0208f208 2020-05-05 stsp change = malloc(sizeof(*change));
625 0208f208 2020-05-05 stsp if (change == NULL) {
626 0208f208 2020-05-05 stsp err = got_error_from_errno("malloc");
630 0208f208 2020-05-05 stsp change->status = GOT_STATUS_NO_CHANGE;
631 0208f208 2020-05-05 stsp if (id1 == NULL)
632 0208f208 2020-05-05 stsp change->status = GOT_STATUS_ADD;
633 0208f208 2020-05-05 stsp else if (id2 == NULL)
634 0208f208 2020-05-05 stsp change->status = GOT_STATUS_DELETE;
636 0208f208 2020-05-05 stsp if (got_object_id_cmp(id1, id2) != 0)
637 0208f208 2020-05-05 stsp change->status = GOT_STATUS_MODIFY;
638 0208f208 2020-05-05 stsp else if (mode1 != mode2)
639 0208f208 2020-05-05 stsp change->status = GOT_STATUS_MODE_CHANGE;
642 0208f208 2020-05-05 stsp err = got_pathlist_insert(NULL, paths, path, change);
645 0208f208 2020-05-05 stsp free(path);
646 0208f208 2020-05-05 stsp free(change);
648 0208f208 2020-05-05 stsp return err;
651 474b4f94 2017-11-30 stsp const struct got_error *
652 474b4f94 2017-11-30 stsp got_diff_tree(struct got_tree_object *tree1, struct got_tree_object *tree2,
653 aaa13589 2019-06-01 stsp const char *label1, const char *label2, struct got_repository *repo,
654 31b4484f 2019-07-27 stsp got_diff_blob_cb cb, void *cb_arg, int diff_content)
656 474b4f94 2017-11-30 stsp const struct got_error *err = NULL;
657 789689b5 2017-11-30 stsp struct got_tree_entry *te1 = NULL;
658 789689b5 2017-11-30 stsp struct got_tree_entry *te2 = NULL;
659 f6861a81 2018-09-13 stsp char *l1 = NULL, *l2 = NULL;
660 56e0773d 2019-11-28 stsp int tidx1 = 0, tidx2 = 0;
662 883f0469 2018-06-23 stsp if (tree1) {
663 56e0773d 2019-11-28 stsp te1 = got_object_tree_get_entry(tree1, 0);
664 60f50a58 2018-09-15 stsp if (te1 && asprintf(&l1, "%s%s%s", label1, label1[0] ? "/" : "",
665 f6861a81 2018-09-13 stsp te1->name) == -1)
666 638f9024 2019-05-13 stsp return got_error_from_errno("asprintf");
668 883f0469 2018-06-23 stsp if (tree2) {
669 56e0773d 2019-11-28 stsp te2 = got_object_tree_get_entry(tree2, 0);
670 60f50a58 2018-09-15 stsp if (te2 && asprintf(&l2, "%s%s%s", label2, label2[0] ? "/" : "",
671 f6861a81 2018-09-13 stsp te2->name) == -1)
672 638f9024 2019-05-13 stsp return got_error_from_errno("asprintf");
677 56e0773d 2019-11-28 stsp struct got_tree_entry *te = NULL;
679 1de5e065 2019-06-01 stsp te = got_object_tree_find_entry(tree2,
680 1de5e065 2019-06-01 stsp te1->name);
684 f6861a81 2018-09-13 stsp if (te && asprintf(&l2, "%s%s%s", label2,
685 f6861a81 2018-09-13 stsp label2[0] ? "/" : "", te->name) == -1)
687 638f9024 2019-05-13 stsp got_error_from_errno("asprintf");
689 aaa13589 2019-06-01 stsp err = diff_entry_old_new(te1, te, l1, l2, repo, cb,
690 31b4484f 2019-07-27 stsp cb_arg, diff_content);
696 56e0773d 2019-11-28 stsp struct got_tree_entry *te = NULL;
698 1de5e065 2019-06-01 stsp te = got_object_tree_find_entry(tree1,
699 1de5e065 2019-06-01 stsp te2->name);
702 d6ce02f1 2018-11-17 stsp if (asprintf(&l2, "%s%s%s", label2,
703 d6ce02f1 2018-11-17 stsp label2[0] ? "/" : "", te->name) == -1)
705 638f9024 2019-05-13 stsp got_error_from_errno("asprintf");
707 d6ce02f1 2018-11-17 stsp if (asprintf(&l2, "%s%s%s", label2,
708 d6ce02f1 2018-11-17 stsp label2[0] ? "/" : "", te2->name) == -1)
710 638f9024 2019-05-13 stsp got_error_from_errno("asprintf");
712 31b4484f 2019-07-27 stsp err = diff_entry_new_old(te2, te, l2, repo,
713 31b4484f 2019-07-27 stsp cb, cb_arg, diff_content);
722 56e0773d 2019-11-28 stsp te1 = got_object_tree_get_entry(tree1, tidx1);
724 f6861a81 2018-09-13 stsp asprintf(&l1, "%s%s%s", label1,
725 f6861a81 2018-09-13 stsp label1[0] ? "/" : "", te1->name) == -1)
726 638f9024 2019-05-13 stsp return got_error_from_errno("asprintf");
732 56e0773d 2019-11-28 stsp te2 = got_object_tree_get_entry(tree2, tidx2);
734 f6861a81 2018-09-13 stsp asprintf(&l2, "%s%s%s", label2,
735 f6861a81 2018-09-13 stsp label2[0] ? "/" : "", te2->name) == -1)
736 638f9024 2019-05-13 stsp return got_error_from_errno("asprintf");
738 474b4f94 2017-11-30 stsp } while (te1 || te2);
740 11528a82 2018-05-19 stsp return err;
743 11528a82 2018-05-19 stsp const struct got_error *
744 15a94983 2018-12-23 stsp got_diff_objects_as_blobs(struct got_object_id *id1, struct got_object_id *id2,
745 54156555 2018-12-24 stsp const char *label1, const char *label2, int diff_context,
746 63035f9f 2019-10-06 stsp int ignore_whitespace, struct got_repository *repo, FILE *outfile)
748 11528a82 2018-05-19 stsp const struct got_error *err;
749 11528a82 2018-05-19 stsp struct got_blob_object *blob1 = NULL, *blob2 = NULL;
751 15a94983 2018-12-23 stsp if (id1 == NULL && id2 == NULL)
752 b74c7625 2018-05-20 stsp return got_error(GOT_ERR_NO_OBJ);
755 15a94983 2018-12-23 stsp err = got_object_open_as_blob(&blob1, repo, id1, 8192);
760 15a94983 2018-12-23 stsp err = got_object_open_as_blob(&blob2, repo, id2, 8192);
764 54156555 2018-12-24 stsp err = got_diff_blob(blob1, blob2, label1, label2, diff_context,
765 63035f9f 2019-10-06 stsp ignore_whitespace, outfile);
768 11528a82 2018-05-19 stsp got_object_blob_close(blob1);
770 11528a82 2018-05-19 stsp got_object_blob_close(blob2);
771 474b4f94 2017-11-30 stsp return err;
774 11528a82 2018-05-19 stsp const struct got_error *
775 15a94983 2018-12-23 stsp got_diff_objects_as_trees(struct got_object_id *id1, struct got_object_id *id2,
776 63035f9f 2019-10-06 stsp char *label1, char *label2, int diff_context, int ignore_whitespace,
777 63035f9f 2019-10-06 stsp struct got_repository *repo, FILE *outfile)
779 11528a82 2018-05-19 stsp const struct got_error *err;
780 11528a82 2018-05-19 stsp struct got_tree_object *tree1 = NULL, *tree2 = NULL;
781 aaa13589 2019-06-01 stsp struct got_diff_blob_output_unidiff_arg arg;
783 15a94983 2018-12-23 stsp if (id1 == NULL && id2 == NULL)
784 b74c7625 2018-05-20 stsp return got_error(GOT_ERR_NO_OBJ);
787 15a94983 2018-12-23 stsp err = got_object_open_as_tree(&tree1, repo, id1);
792 15a94983 2018-12-23 stsp err = got_object_open_as_tree(&tree2, repo, id2);
796 aaa13589 2019-06-01 stsp arg.diff_context = diff_context;
797 63035f9f 2019-10-06 stsp arg.ignore_whitespace = ignore_whitespace;
798 aaa13589 2019-06-01 stsp arg.outfile = outfile;
799 aaa13589 2019-06-01 stsp err = got_diff_tree(tree1, tree2, label1, label2, repo,
800 31b4484f 2019-07-27 stsp got_diff_blob_output_unidiff, &arg, 1);
803 11528a82 2018-05-19 stsp got_object_tree_close(tree1);
805 11528a82 2018-05-19 stsp got_object_tree_close(tree2);
806 11528a82 2018-05-19 stsp return err;
809 11528a82 2018-05-19 stsp const struct got_error *
810 15a94983 2018-12-23 stsp got_diff_objects_as_commits(struct got_object_id *id1,
811 63035f9f 2019-10-06 stsp struct got_object_id *id2, int diff_context, int ignore_whitespace,
812 15a94983 2018-12-23 stsp struct got_repository *repo, FILE *outfile)
814 11528a82 2018-05-19 stsp const struct got_error *err;
815 11528a82 2018-05-19 stsp struct got_commit_object *commit1 = NULL, *commit2 = NULL;
817 15a94983 2018-12-23 stsp if (id2 == NULL)
818 b74c7625 2018-05-20 stsp return got_error(GOT_ERR_NO_OBJ);
821 15a94983 2018-12-23 stsp err = got_object_open_as_commit(&commit1, repo, id1);
826 15a94983 2018-12-23 stsp err = got_object_open_as_commit(&commit2, repo, id2);
830 15a94983 2018-12-23 stsp err = got_diff_objects_as_trees(
831 15a94983 2018-12-23 stsp commit1 ? got_object_commit_get_tree_id(commit1) : NULL,
832 63035f9f 2019-10-06 stsp got_object_commit_get_tree_id(commit2), "", "", diff_context,
833 63035f9f 2019-10-06 stsp ignore_whitespace, repo, outfile);
835 11528a82 2018-05-19 stsp if (commit1)
836 11528a82 2018-05-19 stsp got_object_commit_close(commit1);
837 11528a82 2018-05-19 stsp if (commit2)
838 11528a82 2018-05-19 stsp got_object_commit_close(commit2);
839 11528a82 2018-05-19 stsp return err;
842 dc424a06 2019-08-07 stsp const struct got_error *
843 dc424a06 2019-08-07 stsp got_diff_files(struct got_diff_changes **changes,
844 dc424a06 2019-08-07 stsp struct got_diff_state **ds,
845 dc424a06 2019-08-07 stsp struct got_diff_args **args,
846 dc424a06 2019-08-07 stsp int *flags,
847 dc424a06 2019-08-07 stsp FILE *f1, size_t size1, const char *label1,
848 dc424a06 2019-08-07 stsp FILE *f2, size_t size2, const char *label2,
849 dc424a06 2019-08-07 stsp int diff_context, FILE *outfile)
851 dc424a06 2019-08-07 stsp const struct got_error *err = NULL;
854 dc424a06 2019-08-07 stsp *flags = 0;
855 dc424a06 2019-08-07 stsp *ds = calloc(1, sizeof(**ds));
856 dc424a06 2019-08-07 stsp if (*ds == NULL)
857 dc424a06 2019-08-07 stsp return got_error_from_errno("calloc");
858 dc424a06 2019-08-07 stsp *args = calloc(1, sizeof(**args));
859 dc424a06 2019-08-07 stsp if (*args == NULL) {
860 dc424a06 2019-08-07 stsp err = got_error_from_errno("calloc");
864 dc424a06 2019-08-07 stsp if (changes)
865 dc424a06 2019-08-07 stsp *changes = NULL;
867 dc424a06 2019-08-07 stsp if (f1 == NULL)
868 dc424a06 2019-08-07 stsp *flags |= D_EMPTY1;
870 dc424a06 2019-08-07 stsp if (f2 == NULL)
871 dc424a06 2019-08-07 stsp *flags |= D_EMPTY2;
873 dc424a06 2019-08-07 stsp /* XXX should stat buffers be passed in args instead of ds? */
874 dc424a06 2019-08-07 stsp (*ds)->stb1.st_mode = S_IFREG;
875 dc424a06 2019-08-07 stsp (*ds)->stb1.st_size = size1;
876 dc424a06 2019-08-07 stsp (*ds)->stb1.st_mtime = 0; /* XXX */
878 dc424a06 2019-08-07 stsp (*ds)->stb2.st_mode = S_IFREG;
879 dc424a06 2019-08-07 stsp (*ds)->stb2.st_size = size2;
880 dc424a06 2019-08-07 stsp (*ds)->stb2.st_mtime = 0; /* XXX */
882 dc424a06 2019-08-07 stsp (*args)->diff_format = D_UNIFIED;
883 dc424a06 2019-08-07 stsp (*args)->label[0] = label1;
884 dc424a06 2019-08-07 stsp (*args)->label[1] = label2;
885 dc424a06 2019-08-07 stsp (*args)->diff_context = diff_context;
886 dc424a06 2019-08-07 stsp *flags |= D_PROTOTYPE;
888 dc424a06 2019-08-07 stsp if (outfile) {
889 dc424a06 2019-08-07 stsp fprintf(outfile, "file - %s\n",
890 dc424a06 2019-08-07 stsp f1 == NULL ? "/dev/null" : label1);
891 dc424a06 2019-08-07 stsp fprintf(outfile, "file + %s\n",
892 dc424a06 2019-08-07 stsp f2 == NULL ? "/dev/null" : label2);
894 dc424a06 2019-08-07 stsp if (changes) {
895 dc424a06 2019-08-07 stsp err = alloc_changes(changes);
899 dc424a06 2019-08-07 stsp err = got_diffreg(&res, f1, f2, *flags, *args, *ds, outfile,
900 dc424a06 2019-08-07 stsp changes ? *changes : NULL);
904 dc424a06 2019-08-07 stsp got_diff_state_free(*ds);
906 dc424a06 2019-08-07 stsp *ds = NULL;
908 dc424a06 2019-08-07 stsp if (*args) {
909 dc424a06 2019-08-07 stsp free(*args);
910 dc424a06 2019-08-07 stsp *args = NULL;
912 dc424a06 2019-08-07 stsp if (changes) {
913 dc424a06 2019-08-07 stsp if (*changes)
914 dc424a06 2019-08-07 stsp got_diff_free_changes(*changes);
915 dc424a06 2019-08-07 stsp *changes = NULL;
918 dc424a06 2019-08-07 stsp return err;