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_repository.h"
28 7d283eee 2017-11-29 stsp #include "got_object.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"
33 718b3ab0 2018-03-17 stsp #include "got_lib_diff.h"
34 718b3ab0 2018-03-17 stsp #include "got_lib_path.h"
36 7d283eee 2017-11-29 stsp const struct got_error *
37 7d283eee 2017-11-29 stsp got_diff_blob(struct got_blob_object *blob1, struct got_blob_object *blob2,
38 474b4f94 2017-11-30 stsp const char *label1, const char *label2, FILE *outfile)
40 ed9e98a8 2017-11-29 stsp struct got_diff_state ds;
41 8ba9a219 2017-11-29 stsp struct got_diff_args args;
42 7d283eee 2017-11-29 stsp const struct got_error *err = NULL;
43 4e22badc 2017-11-30 stsp FILE *f1 = NULL, *f2 = NULL;
44 f78b0693 2017-11-29 stsp char hex1[SHA1_DIGEST_STRING_LENGTH];
45 f78b0693 2017-11-29 stsp char hex2[SHA1_DIGEST_STRING_LENGTH];
46 98abbc84 2017-11-30 stsp char *idstr1 = NULL, *idstr2 = NULL;
47 f9d67749 2017-11-30 stsp size_t len, hdrlen;
48 f934cf2c 2018-02-12 stsp size_t size1, size2;
49 4e22badc 2017-11-30 stsp int res, flags = 0;
51 4e22badc 2017-11-30 stsp if (blob1) {
52 a1fd68d8 2018-01-12 stsp f1 = got_opentemp();
53 4e22badc 2017-11-30 stsp if (f1 == NULL)
54 4e22badc 2017-11-30 stsp return got_error(GOT_ERR_FILE_OPEN);
56 4e22badc 2017-11-30 stsp flags |= D_EMPTY1;
58 4e22badc 2017-11-30 stsp if (blob2) {
59 a1fd68d8 2018-01-12 stsp f2 = got_opentemp();
60 4e22badc 2017-11-30 stsp if (f2 == NULL) {
62 4e22badc 2017-11-30 stsp return got_error(GOT_ERR_FILE_OPEN);
65 4e22badc 2017-11-30 stsp flags |= D_EMPTY2;
68 98abbc84 2017-11-30 stsp if (blob1) {
69 f934cf2c 2018-02-12 stsp idstr1 = got_object_blob_id_str(blob1, hex1, sizeof(hex1));
70 f934cf2c 2018-02-12 stsp hdrlen = got_object_blob_get_hdrlen(blob1);
72 eb651edf 2018-02-11 stsp err = got_object_blob_read_block(&len, blob1);
75 eba5c6bb 2018-02-11 stsp if (len == 0)
77 f934cf2c 2018-02-12 stsp size1 += len;
78 4e22badc 2017-11-30 stsp /* Skip blob object header first time around. */
79 dfb54902 2018-04-02 stsp fwrite(got_object_blob_get_read_buf(blob1) + hdrlen,
80 dfb54902 2018-04-02 stsp len - hdrlen, 1, f1);
82 4e22badc 2017-11-30 stsp } while (len != 0);
84 98abbc84 2017-11-30 stsp idstr1 = "/dev/null";
87 98abbc84 2017-11-30 stsp if (blob2) {
88 f934cf2c 2018-02-12 stsp idstr2 = got_object_blob_id_str(blob2, hex2, sizeof(hex2));
89 f934cf2c 2018-02-12 stsp hdrlen = got_object_blob_get_hdrlen(blob2);
91 eb651edf 2018-02-11 stsp err = got_object_blob_read_block(&len, blob2);
94 eba5c6bb 2018-02-11 stsp if (len == 0)
96 f934cf2c 2018-02-12 stsp size2 += len;
97 98abbc84 2017-11-30 stsp /* Skip blob object header first time around. */
98 dfb54902 2018-04-02 stsp fwrite(got_object_blob_get_read_buf(blob2) + hdrlen,
99 dfb54902 2018-04-02 stsp len - hdrlen, 1, f2);
100 98abbc84 2017-11-30 stsp hdrlen = 0;
101 98abbc84 2017-11-30 stsp } while (len != 0);
103 98abbc84 2017-11-30 stsp idstr2 = "/dev/null";
106 eba5c6bb 2018-02-11 stsp fflush(f1);
107 eba5c6bb 2018-02-11 stsp rewind(f1);
110 98abbc84 2017-11-30 stsp fflush(f2);
111 eba5c6bb 2018-02-11 stsp rewind(f2);
114 ed9e98a8 2017-11-29 stsp memset(&ds, 0, sizeof(ds));
115 f9d67749 2017-11-30 stsp /* XXX should stat buffers be passed in args instead of ds? */
116 f9d67749 2017-11-30 stsp ds.stb1.st_mode = S_IFREG;
118 f934cf2c 2018-02-12 stsp ds.stb1.st_size = size1;
119 f9d67749 2017-11-30 stsp ds.stb1.st_mtime = 0; /* XXX */
121 f9d67749 2017-11-30 stsp ds.stb2.st_mode = S_IFREG;
123 f934cf2c 2018-02-12 stsp ds.stb2.st_size = size2;
124 f9d67749 2017-11-30 stsp ds.stb2.st_mtime = 0; /* XXX */
126 f9d67749 2017-11-30 stsp memset(&args, 0, sizeof(args));
127 8ba9a219 2017-11-29 stsp args.diff_format = D_UNIFIED;
128 98abbc84 2017-11-30 stsp args.label[0] = label1 ? label1 : idstr1;
129 98abbc84 2017-11-30 stsp args.label[1] = label2 ? label2 : idstr2;
130 c2c21d46 2018-03-27 stsp args.diff_context = 3;
131 84eb021e 2018-03-27 stsp flags |= D_PROTOTYPE;
133 cb74ff21 2017-11-30 stsp err = got_diffreg(&res, f1, f2, flags, &args, &ds, outfile);
136 98abbc84 2017-11-30 stsp fclose(f1);
138 98abbc84 2017-11-30 stsp fclose(f2);
139 7d283eee 2017-11-29 stsp return err;
142 a3e2cbea 2017-12-01 stsp struct got_tree_entry *
143 a3e2cbea 2017-12-01 stsp match_entry_by_name(struct got_tree_entry *te1, struct got_tree_object *tree2)
145 a3e2cbea 2017-12-01 stsp struct got_tree_entry *te2;
147 a3e2cbea 2017-12-01 stsp SIMPLEQ_FOREACH(te2, &tree2->entries, entry) {
148 a3e2cbea 2017-12-01 stsp if (strcmp(te1->name, te2->name) == 0)
149 a3e2cbea 2017-12-01 stsp return te2;
151 474b4f94 2017-11-30 stsp return NULL;
154 474b4f94 2017-11-30 stsp static const struct got_error *
155 74671950 2018-02-11 stsp diff_added_blob(struct got_object_id *id, struct got_repository *repo,
156 74671950 2018-02-11 stsp FILE *outfile)
158 4e22badc 2017-11-30 stsp const struct got_error *err;
159 2acfca77 2018-04-01 stsp struct got_blob_object *blob = NULL;
160 2acfca77 2018-04-01 stsp struct got_object *obj = NULL;
162 4e22badc 2017-11-30 stsp err = got_object_open(&obj, repo, id);
164 4e22badc 2017-11-30 stsp return err;
166 2acfca77 2018-04-01 stsp err = got_object_blob_open(&blob, repo, obj, 8192);
169 2acfca77 2018-04-01 stsp err = got_diff_blob(NULL, blob, NULL, NULL, outfile);
171 2acfca77 2018-04-01 stsp got_object_close(obj);
173 2acfca77 2018-04-01 stsp got_object_blob_close(blob);
174 2acfca77 2018-04-01 stsp return err;
177 474b4f94 2017-11-30 stsp static const struct got_error *
178 6a213ccb 2017-11-30 stsp diff_modified_blob(struct got_object_id *id1, struct got_object_id *id2,
179 74671950 2018-02-11 stsp struct got_repository *repo, FILE *outfile)
181 6a213ccb 2017-11-30 stsp const struct got_error *err;
182 6a213ccb 2017-11-30 stsp struct got_object *obj1 = NULL;
183 6a213ccb 2017-11-30 stsp struct got_object *obj2 = NULL;
184 6a213ccb 2017-11-30 stsp struct got_blob_object *blob1 = NULL;
185 6a213ccb 2017-11-30 stsp struct got_blob_object *blob2 = NULL;
187 6a213ccb 2017-11-30 stsp err = got_object_open(&obj1, repo, id1);
189 730a8aa0 2018-04-24 stsp return err;
190 eef6493a 2018-01-19 stsp if (got_object_get_type(obj1) != GOT_OBJ_TYPE_BLOB) {
191 6a213ccb 2017-11-30 stsp err = got_error(GOT_ERR_OBJ_TYPE);
195 6a213ccb 2017-11-30 stsp err = got_object_open(&obj2, repo, id2);
198 eef6493a 2018-01-19 stsp if (got_object_get_type(obj2) != GOT_OBJ_TYPE_BLOB) {
199 6a213ccb 2017-11-30 stsp err = got_error(GOT_ERR_BAD_OBJ_DATA);
203 c7020aea 2017-11-30 stsp err = got_object_blob_open(&blob1, repo, obj1, 8192);
207 c7020aea 2017-11-30 stsp err = got_object_blob_open(&blob2, repo, obj2, 8192);
211 74671950 2018-02-11 stsp err = got_diff_blob(blob1, blob2, NULL, NULL, outfile);
215 a3e2cbea 2017-12-01 stsp got_object_close(obj1);
217 a3e2cbea 2017-12-01 stsp got_object_close(obj2);
219 a3e2cbea 2017-12-01 stsp got_object_blob_close(blob1);
221 a3e2cbea 2017-12-01 stsp got_object_blob_close(blob2);
222 6a213ccb 2017-11-30 stsp return err;
225 474b4f94 2017-11-30 stsp static const struct got_error *
226 74671950 2018-02-11 stsp diff_deleted_blob(struct got_object_id *id, struct got_repository *repo,
227 74671950 2018-02-11 stsp FILE *outfile)
229 365fb436 2017-11-30 stsp const struct got_error *err;
230 2acfca77 2018-04-01 stsp struct got_blob_object *blob = NULL;
231 2acfca77 2018-04-01 stsp struct got_object *obj = NULL;
233 365fb436 2017-11-30 stsp err = got_object_open(&obj, repo, id);
235 365fb436 2017-11-30 stsp return err;
237 2acfca77 2018-04-01 stsp err = got_object_blob_open(&blob, repo, obj, 8192);
240 2acfca77 2018-04-01 stsp err = got_diff_blob(blob, NULL, NULL, NULL, outfile);
242 2acfca77 2018-04-01 stsp got_object_close(obj);
244 2acfca77 2018-04-01 stsp got_object_blob_close(blob);
245 2acfca77 2018-04-01 stsp return err;
248 474b4f94 2017-11-30 stsp static const struct got_error *
249 74671950 2018-02-11 stsp diff_added_tree(struct got_object_id *id, struct got_repository *repo,
250 74671950 2018-02-11 stsp FILE *outfile)
252 9c70d4c3 2017-11-30 stsp const struct got_error *err = NULL;
253 9c70d4c3 2017-11-30 stsp struct got_object *treeobj = NULL;
254 9c70d4c3 2017-11-30 stsp struct got_tree_object *tree = NULL;
256 9c70d4c3 2017-11-30 stsp err = got_object_open(&treeobj, repo, id);
260 b107e67f 2018-01-19 stsp if (got_object_get_type(treeobj) != GOT_OBJ_TYPE_TREE) {
261 9c70d4c3 2017-11-30 stsp err = got_error(GOT_ERR_OBJ_TYPE);
265 9c70d4c3 2017-11-30 stsp err = got_object_tree_open(&tree, repo, treeobj);
269 74671950 2018-02-11 stsp err = got_diff_tree(NULL, tree, repo, outfile);
273 9c70d4c3 2017-11-30 stsp got_object_tree_close(tree);
274 9c70d4c3 2017-11-30 stsp if (treeobj)
275 9c70d4c3 2017-11-30 stsp got_object_close(treeobj);
276 9c70d4c3 2017-11-30 stsp return err;
279 474b4f94 2017-11-30 stsp static const struct got_error *
280 789689b5 2017-11-30 stsp diff_modified_tree(struct got_object_id *id1, struct got_object_id *id2,
281 74671950 2018-02-11 stsp struct got_repository *repo, FILE *outfile)
283 789689b5 2017-11-30 stsp const struct got_error *err = NULL;
284 789689b5 2017-11-30 stsp struct got_object *treeobj1 = NULL;
285 789689b5 2017-11-30 stsp struct got_object *treeobj2 = NULL;
286 789689b5 2017-11-30 stsp struct got_tree_object *tree1 = NULL;
287 789689b5 2017-11-30 stsp struct got_tree_object *tree2 = NULL;
289 789689b5 2017-11-30 stsp err = got_object_open(&treeobj1, repo, id1);
293 eef6493a 2018-01-19 stsp if (got_object_get_type(treeobj1) != GOT_OBJ_TYPE_TREE) {
294 789689b5 2017-11-30 stsp err = got_error(GOT_ERR_OBJ_TYPE);
298 789689b5 2017-11-30 stsp err = got_object_open(&treeobj2, repo, id2);
302 eef6493a 2018-01-19 stsp if (got_object_get_type(treeobj2) != GOT_OBJ_TYPE_TREE) {
303 789689b5 2017-11-30 stsp err = got_error(GOT_ERR_OBJ_TYPE);
307 789689b5 2017-11-30 stsp err = got_object_tree_open(&tree1, repo, treeobj1);
311 789689b5 2017-11-30 stsp err = got_object_tree_open(&tree2, repo, treeobj2);
315 74671950 2018-02-11 stsp err = got_diff_tree(tree1, tree2, repo, outfile);
319 789689b5 2017-11-30 stsp got_object_tree_close(tree1);
321 789689b5 2017-11-30 stsp got_object_tree_close(tree2);
322 789689b5 2017-11-30 stsp if (treeobj1)
323 789689b5 2017-11-30 stsp got_object_close(treeobj1);
324 789689b5 2017-11-30 stsp if (treeobj2)
325 789689b5 2017-11-30 stsp got_object_close(treeobj2);
326 789689b5 2017-11-30 stsp return err;
329 474b4f94 2017-11-30 stsp static const struct got_error *
330 74671950 2018-02-11 stsp diff_deleted_tree(struct got_object_id *id, struct got_repository *repo, FILE *outfile)
332 2c56f2ce 2017-11-30 stsp const struct got_error *err = NULL;
333 2c56f2ce 2017-11-30 stsp struct got_object *treeobj = NULL;
334 2c56f2ce 2017-11-30 stsp struct got_tree_object *tree = NULL;
336 2c56f2ce 2017-11-30 stsp err = got_object_open(&treeobj, repo, id);
340 b107e67f 2018-01-19 stsp if (got_object_get_type(treeobj) != GOT_OBJ_TYPE_TREE) {
341 2c56f2ce 2017-11-30 stsp err = got_error(GOT_ERR_OBJ_TYPE);
345 2c56f2ce 2017-11-30 stsp err = got_object_tree_open(&tree, repo, treeobj);
349 74671950 2018-02-11 stsp err = got_diff_tree(tree, NULL, repo, outfile);
353 2c56f2ce 2017-11-30 stsp got_object_tree_close(tree);
354 2c56f2ce 2017-11-30 stsp if (treeobj)
355 2c56f2ce 2017-11-30 stsp got_object_close(treeobj);
356 2c56f2ce 2017-11-30 stsp return err;
359 474b4f94 2017-11-30 stsp static const struct got_error *
360 74671950 2018-02-11 stsp diff_kind_mismatch(struct got_object_id *id1, struct got_object_id *id2,
361 74671950 2018-02-11 stsp FILE *outfile)
363 013404a9 2017-11-30 stsp /* XXX TODO */
364 474b4f94 2017-11-30 stsp return NULL;
367 474b4f94 2017-11-30 stsp static const struct got_error *
368 6a213ccb 2017-11-30 stsp diff_entry_old_new(struct got_tree_entry *te1, struct got_tree_object *tree2,
369 74671950 2018-02-11 stsp struct got_repository *repo, FILE *outfile)
371 07ccb00b 2018-03-27 stsp struct got_tree_entry *te2 = NULL;
374 07ccb00b 2018-03-27 stsp te2 = match_entry_by_name(te1, tree2);
375 474b4f94 2017-11-30 stsp if (te2 == NULL) {
376 474b4f94 2017-11-30 stsp if (S_ISDIR(te1->mode))
377 59ece79d 2018-02-12 stsp return diff_deleted_tree(te1->id, repo, outfile);
378 59ece79d 2018-02-12 stsp return diff_deleted_blob(te1->id, repo, outfile);
381 4209f790 2017-11-30 stsp if (S_ISDIR(te1->mode) && S_ISDIR(te2->mode)) {
382 59ece79d 2018-02-12 stsp if (got_object_id_cmp(te1->id, te2->id) != 0)
383 59ece79d 2018-02-12 stsp return diff_modified_tree(te1->id, te2->id, repo,
385 4209f790 2017-11-30 stsp } else if (S_ISREG(te1->mode) && S_ISREG(te2->mode)) {
386 59ece79d 2018-02-12 stsp if (got_object_id_cmp(te1->id, te2->id) != 0)
387 59ece79d 2018-02-12 stsp return diff_modified_blob(te1->id, te2->id, repo,
391 59ece79d 2018-02-12 stsp return diff_kind_mismatch(te1->id, te2->id, outfile);
394 474b4f94 2017-11-30 stsp static const struct got_error *
395 4e22badc 2017-11-30 stsp diff_entry_new_old(struct got_tree_entry *te2, struct got_tree_object *tree1,
396 74671950 2018-02-11 stsp struct got_repository *repo, FILE *outfile)
398 07ccb00b 2018-03-27 stsp if (tree1) {
399 07ccb00b 2018-03-27 stsp struct got_tree_entry *te1 = match_entry_by_name(te2, tree1);
400 07ccb00b 2018-03-27 stsp if (te1 != NULL) /* handled by diff_entry_old_new() */
401 07ccb00b 2018-03-27 stsp return NULL;
404 474b4f94 2017-11-30 stsp if (S_ISDIR(te2->mode))
405 59ece79d 2018-02-12 stsp return diff_added_tree(te2->id, repo, outfile);
406 59ece79d 2018-02-12 stsp return diff_added_blob(te2->id, repo, outfile);
409 474b4f94 2017-11-30 stsp const struct got_error *
410 474b4f94 2017-11-30 stsp got_diff_tree(struct got_tree_object *tree1, struct got_tree_object *tree2,
411 74671950 2018-02-11 stsp struct got_repository *repo, FILE *outfile)
413 474b4f94 2017-11-30 stsp const struct got_error *err = NULL;
414 789689b5 2017-11-30 stsp struct got_tree_entry *te1 = NULL;
415 789689b5 2017-11-30 stsp struct got_tree_entry *te2 = NULL;
418 789689b5 2017-11-30 stsp te1 = SIMPLEQ_FIRST(&tree1->entries);
420 789689b5 2017-11-30 stsp te2 = SIMPLEQ_FIRST(&tree2->entries);
424 74671950 2018-02-11 stsp err = diff_entry_old_new(te1, tree2, repo, outfile);
430 74671950 2018-02-11 stsp err = diff_entry_new_old(te2, tree1, repo, outfile);
436 474b4f94 2017-11-30 stsp te1 = SIMPLEQ_NEXT(te1, entry);
438 474b4f94 2017-11-30 stsp te2 = SIMPLEQ_NEXT(te2, entry);
439 474b4f94 2017-11-30 stsp } while (te1 || te2);
441 11528a82 2018-05-19 stsp return err;
444 11528a82 2018-05-19 stsp const struct got_error *
445 11528a82 2018-05-19 stsp got_diff_objects_as_blobs(struct got_object *obj1, struct got_object *obj2,
446 11528a82 2018-05-19 stsp struct got_repository *repo, FILE *outfile)
448 11528a82 2018-05-19 stsp const struct got_error *err;
449 11528a82 2018-05-19 stsp struct got_blob_object *blob1 = NULL, *blob2 = NULL;
451 11528a82 2018-05-19 stsp err = got_object_blob_open(&blob1, repo, obj1, 8192);
454 11528a82 2018-05-19 stsp err = got_object_blob_open(&blob2, repo, obj2, 8192);
458 11528a82 2018-05-19 stsp err = got_diff_blob(blob1, blob2, NULL, NULL, outfile);
461 11528a82 2018-05-19 stsp got_object_blob_close(blob1);
463 11528a82 2018-05-19 stsp got_object_blob_close(blob2);
464 474b4f94 2017-11-30 stsp return err;
467 11528a82 2018-05-19 stsp const struct got_error *
468 11528a82 2018-05-19 stsp got_diff_objects_as_trees(struct got_object *obj1, struct got_object *obj2,
469 11528a82 2018-05-19 stsp struct got_repository *repo, FILE *outfile)
471 11528a82 2018-05-19 stsp const struct got_error *err;
472 11528a82 2018-05-19 stsp struct got_tree_object *tree1 = NULL, *tree2 = NULL;
474 11528a82 2018-05-19 stsp err = got_object_tree_open(&tree1, repo, obj1);
477 11528a82 2018-05-19 stsp err = got_object_tree_open(&tree2, repo, obj2);
481 11528a82 2018-05-19 stsp err = got_diff_tree(tree1, tree2, repo, outfile);
484 11528a82 2018-05-19 stsp got_object_tree_close(tree1);
486 11528a82 2018-05-19 stsp got_object_tree_close(tree2);
487 11528a82 2018-05-19 stsp return err;
490 11528a82 2018-05-19 stsp const struct got_error *
491 11528a82 2018-05-19 stsp got_diff_objects_as_commits(struct got_object *obj1, struct got_object *obj2,
492 11528a82 2018-05-19 stsp struct got_repository *repo, FILE *outfile)
494 11528a82 2018-05-19 stsp const struct got_error *err;
495 11528a82 2018-05-19 stsp struct got_commit_object *commit1 = NULL, *commit2 = NULL;
496 11528a82 2018-05-19 stsp struct got_object *tree_obj1 = NULL, *tree_obj2 = NULL;
498 11528a82 2018-05-19 stsp err = got_object_commit_open(&commit1, repo, obj1);
501 11528a82 2018-05-19 stsp err = got_object_commit_open(&commit2, repo, obj2);
505 11528a82 2018-05-19 stsp err = got_object_open(&tree_obj1, repo, commit1->tree_id);
508 11528a82 2018-05-19 stsp err = got_object_open(&tree_obj2, repo, commit2->tree_id);
512 11528a82 2018-05-19 stsp err = got_diff_objects_as_trees(tree_obj1, tree_obj2, repo, outfile);
514 11528a82 2018-05-19 stsp if (tree_obj1)
515 11528a82 2018-05-19 stsp got_object_close(tree_obj1);
516 11528a82 2018-05-19 stsp if (tree_obj2)
517 11528a82 2018-05-19 stsp got_object_close(tree_obj2);
518 11528a82 2018-05-19 stsp if (commit1)
519 11528a82 2018-05-19 stsp got_object_commit_close(commit1);
520 11528a82 2018-05-19 stsp if (commit2)
521 11528a82 2018-05-19 stsp got_object_commit_close(commit2);
522 11528a82 2018-05-19 stsp return err;