Blame


1 7d283eee 2017-11-29 stsp /*
2 7d283eee 2017-11-29 stsp * Copyright (c) 2017 Stefan Sperling <stsp@openbsd.org>
3 7d283eee 2017-11-29 stsp *
4 7d283eee 2017-11-29 stsp * Permission to use, copy, modify, and distribute this software for any
5 7d283eee 2017-11-29 stsp * purpose with or without fee is hereby granted, provided that the above
6 7d283eee 2017-11-29 stsp * copyright notice and this permission notice appear in all copies.
7 7d283eee 2017-11-29 stsp *
8 7d283eee 2017-11-29 stsp * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 7d283eee 2017-11-29 stsp * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 7d283eee 2017-11-29 stsp * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 7d283eee 2017-11-29 stsp * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 7d283eee 2017-11-29 stsp * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 7d283eee 2017-11-29 stsp * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 7d283eee 2017-11-29 stsp * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 7d283eee 2017-11-29 stsp */
16 7d283eee 2017-11-29 stsp
17 7d283eee 2017-11-29 stsp #include <sys/queue.h>
18 1c7f0520 2017-11-29 stsp #include <sys/stat.h>
19 7d283eee 2017-11-29 stsp
20 7d283eee 2017-11-29 stsp #include <stdio.h>
21 7d283eee 2017-11-29 stsp #include <stdlib.h>
22 7d283eee 2017-11-29 stsp #include <string.h>
23 f9d67749 2017-11-30 stsp #include <limits.h>
24 7d283eee 2017-11-29 stsp #include <sha1.h>
25 7d283eee 2017-11-29 stsp #include <zlib.h>
26 7d283eee 2017-11-29 stsp
27 7d283eee 2017-11-29 stsp #include "got_object.h"
28 e09a504c 2019-06-28 stsp #include "got_repository.h"
29 7d283eee 2017-11-29 stsp #include "got_error.h"
30 789689b5 2017-11-30 stsp #include "got_diff.h"
31 511a516b 2018-05-19 stsp #include "got_opentemp.h"
32 324d37e7 2019-05-11 stsp #include "got_path.h"
33 7d283eee 2017-11-29 stsp
34 718b3ab0 2018-03-17 stsp #include "got_lib_diff.h"
35 15a94983 2018-12-23 stsp #include "got_lib_delta.h"
36 15a94983 2018-12-23 stsp #include "got_lib_inflate.h"
37 15a94983 2018-12-23 stsp #include "got_lib_object.h"
38 a7852263 2017-11-30 stsp
39 404c43c4 2018-06-21 stsp static const struct got_error *
40 404c43c4 2018-06-21 stsp diff_blobs(struct got_blob_object *blob1, struct got_blob_object *blob2,
41 54156555 2018-12-24 stsp const char *label1, const char *label2, int diff_context, FILE *outfile,
42 54156555 2018-12-24 stsp struct got_diff_changes *changes)
43 7d283eee 2017-11-29 stsp {
44 ed9e98a8 2017-11-29 stsp struct got_diff_state ds;
45 8ba9a219 2017-11-29 stsp struct got_diff_args args;
46 7d283eee 2017-11-29 stsp const struct got_error *err = NULL;
47 4e22badc 2017-11-30 stsp FILE *f1 = NULL, *f2 = NULL;
48 f78b0693 2017-11-29 stsp char hex1[SHA1_DIGEST_STRING_LENGTH];
49 f78b0693 2017-11-29 stsp char hex2[SHA1_DIGEST_STRING_LENGTH];
50 98abbc84 2017-11-30 stsp char *idstr1 = NULL, *idstr2 = NULL;
51 f934cf2c 2018-02-12 stsp size_t size1, size2;
52 4e22badc 2017-11-30 stsp int res, flags = 0;
53 7d283eee 2017-11-29 stsp
54 4e22badc 2017-11-30 stsp if (blob1) {
55 a1fd68d8 2018-01-12 stsp f1 = got_opentemp();
56 4e22badc 2017-11-30 stsp if (f1 == NULL)
57 638f9024 2019-05-13 stsp return got_error_from_errno("got_opentemp");
58 4e22badc 2017-11-30 stsp } else
59 4e22badc 2017-11-30 stsp flags |= D_EMPTY1;
60 7d283eee 2017-11-29 stsp
61 4e22badc 2017-11-30 stsp if (blob2) {
62 a1fd68d8 2018-01-12 stsp f2 = got_opentemp();
63 4e22badc 2017-11-30 stsp if (f2 == NULL) {
64 638f9024 2019-05-13 stsp err = got_error_from_errno("got_opentemp");
65 4e22badc 2017-11-30 stsp fclose(f1);
66 fb43ecf1 2019-02-11 stsp return err;
67 4e22badc 2017-11-30 stsp }
68 4e22badc 2017-11-30 stsp } else
69 4e22badc 2017-11-30 stsp flags |= D_EMPTY2;
70 7d283eee 2017-11-29 stsp
71 f934cf2c 2018-02-12 stsp size1 = 0;
72 98abbc84 2017-11-30 stsp if (blob1) {
73 f934cf2c 2018-02-12 stsp idstr1 = got_object_blob_id_str(blob1, hex1, sizeof(hex1));
74 6c4c42e0 2019-06-24 stsp err = got_object_blob_dump_to_file(&size1, NULL, NULL, f1,
75 6c4c42e0 2019-06-24 stsp blob1);
76 35e9ba5d 2018-06-21 stsp if (err)
77 35e9ba5d 2018-06-21 stsp goto done;
78 98abbc84 2017-11-30 stsp } else
79 98abbc84 2017-11-30 stsp idstr1 = "/dev/null";
80 7d283eee 2017-11-29 stsp
81 f934cf2c 2018-02-12 stsp size2 = 0;
82 98abbc84 2017-11-30 stsp if (blob2) {
83 f934cf2c 2018-02-12 stsp idstr2 = got_object_blob_id_str(blob2, hex2, sizeof(hex2));
84 6c4c42e0 2019-06-24 stsp err = got_object_blob_dump_to_file(&size2, NULL, NULL, f2,
85 6c4c42e0 2019-06-24 stsp blob2);
86 35e9ba5d 2018-06-21 stsp if (err)
87 35e9ba5d 2018-06-21 stsp goto done;
88 98abbc84 2017-11-30 stsp } else
89 98abbc84 2017-11-30 stsp idstr2 = "/dev/null";
90 7d283eee 2017-11-29 stsp
91 ed9e98a8 2017-11-29 stsp memset(&ds, 0, sizeof(ds));
92 f9d67749 2017-11-30 stsp /* XXX should stat buffers be passed in args instead of ds? */
93 f9d67749 2017-11-30 stsp ds.stb1.st_mode = S_IFREG;
94 98abbc84 2017-11-30 stsp if (blob1)
95 f934cf2c 2018-02-12 stsp ds.stb1.st_size = size1;
96 f9d67749 2017-11-30 stsp ds.stb1.st_mtime = 0; /* XXX */
97 8ba9a219 2017-11-29 stsp
98 f9d67749 2017-11-30 stsp ds.stb2.st_mode = S_IFREG;
99 98abbc84 2017-11-30 stsp if (blob2)
100 f934cf2c 2018-02-12 stsp ds.stb2.st_size = size2;
101 f9d67749 2017-11-30 stsp ds.stb2.st_mtime = 0; /* XXX */
102 f9d67749 2017-11-30 stsp
103 54156555 2018-12-24 stsp memset(&args, 0, sizeof(args));
104 8ba9a219 2017-11-29 stsp args.diff_format = D_UNIFIED;
105 54156555 2018-12-24 stsp args.label[0] = label1 ? label1 : idstr1;
106 54156555 2018-12-24 stsp args.label[1] = label2 ? label2 : idstr2;
107 df2871d2 2018-10-18 stsp args.diff_context = diff_context;
108 84eb021e 2018-03-27 stsp flags |= D_PROTOTYPE;
109 62136d3a 2017-11-29 stsp
110 09de383e 2018-12-24 stsp if (outfile) {
111 09de383e 2018-12-24 stsp fprintf(outfile, "blob - %s\n", idstr1);
112 09de383e 2018-12-24 stsp fprintf(outfile, "blob + %s\n", idstr2);
113 09de383e 2018-12-24 stsp }
114 404c43c4 2018-06-21 stsp err = got_diffreg(&res, f1, f2, flags, &args, &ds, outfile, changes);
115 7d283eee 2017-11-29 stsp done:
116 fb43ecf1 2019-02-11 stsp if (f1 && fclose(f1) != 0 && err == NULL)
117 638f9024 2019-05-13 stsp err = got_error_from_errno("fclose");
118 fb43ecf1 2019-02-11 stsp if (f2 && fclose(f2) != 0 && err == NULL)
119 638f9024 2019-05-13 stsp err = got_error_from_errno("fclose");
120 7d283eee 2017-11-29 stsp return err;
121 aaa13589 2019-06-01 stsp }
122 aaa13589 2019-06-01 stsp
123 aaa13589 2019-06-01 stsp const struct got_error *
124 aaa13589 2019-06-01 stsp got_diff_blob_output_unidiff(void *arg, struct got_blob_object *blob1,
125 aaa13589 2019-06-01 stsp struct got_blob_object *blob2, struct got_object_id *id1,
126 aaa13589 2019-06-01 stsp struct got_object_id *id2, const char *label1, const char *label2,
127 aaa13589 2019-06-01 stsp struct got_repository *repo)
128 aaa13589 2019-06-01 stsp {
129 aaa13589 2019-06-01 stsp struct got_diff_blob_output_unidiff_arg *a = arg;
130 aaa13589 2019-06-01 stsp
131 aaa13589 2019-06-01 stsp return diff_blobs(blob1, blob2, label1, label2, a->diff_context,
132 aaa13589 2019-06-01 stsp a->outfile, NULL);
133 7d283eee 2017-11-29 stsp }
134 474b4f94 2017-11-30 stsp
135 404c43c4 2018-06-21 stsp const struct got_error *
136 404c43c4 2018-06-21 stsp got_diff_blob(struct got_blob_object *blob1, struct got_blob_object *blob2,
137 54156555 2018-12-24 stsp const char *label1, const char *label2, int diff_context, FILE *outfile)
138 404c43c4 2018-06-21 stsp {
139 54156555 2018-12-24 stsp return diff_blobs(blob1, blob2, label1, label2, diff_context, outfile,
140 54156555 2018-12-24 stsp NULL);
141 404c43c4 2018-06-21 stsp }
142 404c43c4 2018-06-21 stsp
143 404c43c4 2018-06-21 stsp const struct got_error *
144 b72f483a 2019-02-05 stsp got_diff_blob_file(struct got_blob_object *blob1, FILE *f2, size_t size2,
145 b72f483a 2019-02-05 stsp const char *label2, int diff_context, FILE *outfile)
146 b72f483a 2019-02-05 stsp {
147 b72f483a 2019-02-05 stsp struct got_diff_state ds;
148 b72f483a 2019-02-05 stsp struct got_diff_args args;
149 b72f483a 2019-02-05 stsp const struct got_error *err = NULL;
150 b72f483a 2019-02-05 stsp FILE *f1 = NULL;
151 b72f483a 2019-02-05 stsp char hex1[SHA1_DIGEST_STRING_LENGTH];
152 b72f483a 2019-02-05 stsp char *idstr1 = NULL;
153 b72f483a 2019-02-05 stsp size_t size1;
154 b72f483a 2019-02-05 stsp int res, flags = 0;
155 b72f483a 2019-02-05 stsp
156 b72f483a 2019-02-05 stsp size1 = 0;
157 b72f483a 2019-02-05 stsp if (blob1) {
158 b72f483a 2019-02-05 stsp f1 = got_opentemp();
159 b72f483a 2019-02-05 stsp if (f1 == NULL)
160 638f9024 2019-05-13 stsp return got_error_from_errno("got_opentemp");
161 b72f483a 2019-02-05 stsp idstr1 = got_object_blob_id_str(blob1, hex1, sizeof(hex1));
162 6c4c42e0 2019-06-24 stsp err = got_object_blob_dump_to_file(&size1, NULL, NULL, f1,
163 6c4c42e0 2019-06-24 stsp blob1);
164 b72f483a 2019-02-05 stsp if (err)
165 b72f483a 2019-02-05 stsp goto done;
166 b72f483a 2019-02-05 stsp } else {
167 b72f483a 2019-02-05 stsp flags |= D_EMPTY1;
168 b72f483a 2019-02-05 stsp idstr1 = "/dev/null";
169 b72f483a 2019-02-05 stsp }
170 b72f483a 2019-02-05 stsp
171 b72f483a 2019-02-05 stsp if (f2 == NULL)
172 b72f483a 2019-02-05 stsp flags |= D_EMPTY2;
173 b72f483a 2019-02-05 stsp
174 b72f483a 2019-02-05 stsp memset(&ds, 0, sizeof(ds));
175 b72f483a 2019-02-05 stsp /* XXX should stat buffers be passed in args instead of ds? */
176 b72f483a 2019-02-05 stsp ds.stb1.st_mode = S_IFREG;
177 b72f483a 2019-02-05 stsp if (blob1)
178 b72f483a 2019-02-05 stsp ds.stb1.st_size = size1;
179 b72f483a 2019-02-05 stsp ds.stb1.st_mtime = 0; /* XXX */
180 b72f483a 2019-02-05 stsp
181 b72f483a 2019-02-05 stsp ds.stb2.st_mode = S_IFREG;
182 b72f483a 2019-02-05 stsp ds.stb2.st_size = size2;
183 b72f483a 2019-02-05 stsp ds.stb2.st_mtime = 0; /* XXX */
184 b72f483a 2019-02-05 stsp
185 b72f483a 2019-02-05 stsp memset(&args, 0, sizeof(args));
186 b72f483a 2019-02-05 stsp args.diff_format = D_UNIFIED;
187 b72f483a 2019-02-05 stsp args.label[0] = label2;
188 b72f483a 2019-02-05 stsp args.label[1] = label2;
189 b72f483a 2019-02-05 stsp args.diff_context = diff_context;
190 b72f483a 2019-02-05 stsp flags |= D_PROTOTYPE;
191 b72f483a 2019-02-05 stsp
192 b72f483a 2019-02-05 stsp fprintf(outfile, "blob - %s\n", idstr1);
193 049da17d 2019-03-26 stsp fprintf(outfile, "file + %s\n", f2 == NULL ? "/dev/null" : label2);
194 b72f483a 2019-02-05 stsp err = got_diffreg(&res, f1, f2, flags, &args, &ds, outfile, NULL);
195 b72f483a 2019-02-05 stsp done:
196 fb43ecf1 2019-02-11 stsp if (f1 && fclose(f1) != 0 && err == NULL)
197 638f9024 2019-05-13 stsp err = got_error_from_errno("fclose");
198 b72f483a 2019-02-05 stsp return err;
199 b72f483a 2019-02-05 stsp }
200 b72f483a 2019-02-05 stsp
201 b72f483a 2019-02-05 stsp const struct got_error *
202 404c43c4 2018-06-21 stsp got_diff_blob_lines_changed(struct got_diff_changes **changes,
203 404c43c4 2018-06-21 stsp struct got_blob_object *blob1, struct got_blob_object *blob2)
204 404c43c4 2018-06-21 stsp {
205 404c43c4 2018-06-21 stsp const struct got_error *err = NULL;
206 404c43c4 2018-06-21 stsp
207 404c43c4 2018-06-21 stsp *changes = calloc(1, sizeof(**changes));
208 404c43c4 2018-06-21 stsp if (*changes == NULL)
209 638f9024 2019-05-13 stsp return got_error_from_errno("calloc");
210 404c43c4 2018-06-21 stsp SIMPLEQ_INIT(&(*changes)->entries);
211 404c43c4 2018-06-21 stsp
212 54156555 2018-12-24 stsp err = diff_blobs(blob1, blob2, NULL, NULL, 3, NULL, *changes);
213 404c43c4 2018-06-21 stsp if (err) {
214 404c43c4 2018-06-21 stsp got_diff_free_changes(*changes);
215 404c43c4 2018-06-21 stsp *changes = NULL;
216 404c43c4 2018-06-21 stsp }
217 404c43c4 2018-06-21 stsp return err;
218 404c43c4 2018-06-21 stsp }
219 404c43c4 2018-06-21 stsp
220 404c43c4 2018-06-21 stsp void
221 404c43c4 2018-06-21 stsp got_diff_free_changes(struct got_diff_changes *changes)
222 404c43c4 2018-06-21 stsp {
223 404c43c4 2018-06-21 stsp struct got_diff_change *change;
224 404c43c4 2018-06-21 stsp while (!SIMPLEQ_EMPTY(&changes->entries)) {
225 404c43c4 2018-06-21 stsp change = SIMPLEQ_FIRST(&changes->entries);
226 404c43c4 2018-06-21 stsp SIMPLEQ_REMOVE_HEAD(&changes->entries, entry);
227 404c43c4 2018-06-21 stsp free(change);
228 404c43c4 2018-06-21 stsp }
229 404c43c4 2018-06-21 stsp free(changes);
230 474b4f94 2017-11-30 stsp }
231 474b4f94 2017-11-30 stsp
232 474b4f94 2017-11-30 stsp static const struct got_error *
233 54156555 2018-12-24 stsp diff_added_blob(struct got_object_id *id, const char *label,
234 aaa13589 2019-06-01 stsp struct got_repository *repo, got_diff_blob_cb cb, void *cb_arg)
235 474b4f94 2017-11-30 stsp {
236 4e22badc 2017-11-30 stsp const struct got_error *err;
237 2acfca77 2018-04-01 stsp struct got_blob_object *blob = NULL;
238 2acfca77 2018-04-01 stsp struct got_object *obj = NULL;
239 4e22badc 2017-11-30 stsp
240 4e22badc 2017-11-30 stsp err = got_object_open(&obj, repo, id);
241 4e22badc 2017-11-30 stsp if (err)
242 4e22badc 2017-11-30 stsp return err;
243 4e22badc 2017-11-30 stsp
244 2acfca77 2018-04-01 stsp err = got_object_blob_open(&blob, repo, obj, 8192);
245 2acfca77 2018-04-01 stsp if (err)
246 2acfca77 2018-04-01 stsp goto done;
247 aaa13589 2019-06-01 stsp err = cb(cb_arg, NULL, blob, NULL, id, NULL, label, repo);
248 2acfca77 2018-04-01 stsp done:
249 2acfca77 2018-04-01 stsp got_object_close(obj);
250 2acfca77 2018-04-01 stsp if (blob)
251 2acfca77 2018-04-01 stsp got_object_blob_close(blob);
252 2acfca77 2018-04-01 stsp return err;
253 474b4f94 2017-11-30 stsp }
254 474b4f94 2017-11-30 stsp
255 474b4f94 2017-11-30 stsp static const struct got_error *
256 6a213ccb 2017-11-30 stsp diff_modified_blob(struct got_object_id *id1, struct got_object_id *id2,
257 aaa13589 2019-06-01 stsp const char *label1, const char *label2, struct got_repository *repo,
258 aaa13589 2019-06-01 stsp got_diff_blob_cb cb, void *cb_arg)
259 474b4f94 2017-11-30 stsp {
260 6a213ccb 2017-11-30 stsp const struct got_error *err;
261 6a213ccb 2017-11-30 stsp struct got_object *obj1 = NULL;
262 6a213ccb 2017-11-30 stsp struct got_object *obj2 = NULL;
263 6a213ccb 2017-11-30 stsp struct got_blob_object *blob1 = NULL;
264 6a213ccb 2017-11-30 stsp struct got_blob_object *blob2 = NULL;
265 6a213ccb 2017-11-30 stsp
266 6a213ccb 2017-11-30 stsp err = got_object_open(&obj1, repo, id1);
267 6a213ccb 2017-11-30 stsp if (err)
268 730a8aa0 2018-04-24 stsp return err;
269 15a94983 2018-12-23 stsp if (obj1->type != GOT_OBJ_TYPE_BLOB) {
270 6a213ccb 2017-11-30 stsp err = got_error(GOT_ERR_OBJ_TYPE);
271 6a213ccb 2017-11-30 stsp goto done;
272 6a213ccb 2017-11-30 stsp }
273 6a213ccb 2017-11-30 stsp
274 6a213ccb 2017-11-30 stsp err = got_object_open(&obj2, repo, id2);
275 730a8aa0 2018-04-24 stsp if (err)
276 6a213ccb 2017-11-30 stsp goto done;
277 15a94983 2018-12-23 stsp if (obj2->type != GOT_OBJ_TYPE_BLOB) {
278 6a213ccb 2017-11-30 stsp err = got_error(GOT_ERR_BAD_OBJ_DATA);
279 6a213ccb 2017-11-30 stsp goto done;
280 6a213ccb 2017-11-30 stsp }
281 6a213ccb 2017-11-30 stsp
282 c7020aea 2017-11-30 stsp err = got_object_blob_open(&blob1, repo, obj1, 8192);
283 2acfca77 2018-04-01 stsp if (err)
284 6a213ccb 2017-11-30 stsp goto done;
285 6a213ccb 2017-11-30 stsp
286 c7020aea 2017-11-30 stsp err = got_object_blob_open(&blob2, repo, obj2, 8192);
287 2acfca77 2018-04-01 stsp if (err)
288 6a213ccb 2017-11-30 stsp goto done;
289 6a213ccb 2017-11-30 stsp
290 aaa13589 2019-06-01 stsp err = cb(cb_arg, blob1, blob2, id1, id2, label1, label2, repo);
291 6a213ccb 2017-11-30 stsp done:
292 a3e2cbea 2017-12-01 stsp if (obj1)
293 a3e2cbea 2017-12-01 stsp got_object_close(obj1);
294 a3e2cbea 2017-12-01 stsp if (obj2)
295 a3e2cbea 2017-12-01 stsp got_object_close(obj2);
296 a3e2cbea 2017-12-01 stsp if (blob1)
297 a3e2cbea 2017-12-01 stsp got_object_blob_close(blob1);
298 a3e2cbea 2017-12-01 stsp if (blob2)
299 a3e2cbea 2017-12-01 stsp got_object_blob_close(blob2);
300 6a213ccb 2017-11-30 stsp return err;
301 474b4f94 2017-11-30 stsp }
302 474b4f94 2017-11-30 stsp
303 474b4f94 2017-11-30 stsp static const struct got_error *
304 f6861a81 2018-09-13 stsp diff_deleted_blob(struct got_object_id *id, const char *label,
305 aaa13589 2019-06-01 stsp struct got_repository *repo, got_diff_blob_cb cb, void *cb_arg)
306 474b4f94 2017-11-30 stsp {
307 365fb436 2017-11-30 stsp const struct got_error *err;
308 2acfca77 2018-04-01 stsp struct got_blob_object *blob = NULL;
309 2acfca77 2018-04-01 stsp struct got_object *obj = NULL;
310 365fb436 2017-11-30 stsp
311 365fb436 2017-11-30 stsp err = got_object_open(&obj, repo, id);
312 365fb436 2017-11-30 stsp if (err)
313 365fb436 2017-11-30 stsp return err;
314 365fb436 2017-11-30 stsp
315 2acfca77 2018-04-01 stsp err = got_object_blob_open(&blob, repo, obj, 8192);
316 2acfca77 2018-04-01 stsp if (err)
317 2acfca77 2018-04-01 stsp goto done;
318 aaa13589 2019-06-01 stsp err = cb(cb_arg, blob, NULL, id, NULL, label, NULL, repo);
319 2acfca77 2018-04-01 stsp done:
320 2acfca77 2018-04-01 stsp got_object_close(obj);
321 2acfca77 2018-04-01 stsp if (blob)
322 2acfca77 2018-04-01 stsp got_object_blob_close(blob);
323 2acfca77 2018-04-01 stsp return err;
324 474b4f94 2017-11-30 stsp }
325 474b4f94 2017-11-30 stsp
326 474b4f94 2017-11-30 stsp static const struct got_error *
327 54156555 2018-12-24 stsp diff_added_tree(struct got_object_id *id, const char *label,
328 aaa13589 2019-06-01 stsp struct got_repository *repo, got_diff_blob_cb cb, void *cb_arg)
329 474b4f94 2017-11-30 stsp {
330 9c70d4c3 2017-11-30 stsp const struct got_error *err = NULL;
331 9c70d4c3 2017-11-30 stsp struct got_object *treeobj = NULL;
332 9c70d4c3 2017-11-30 stsp struct got_tree_object *tree = NULL;
333 9c70d4c3 2017-11-30 stsp
334 9c70d4c3 2017-11-30 stsp err = got_object_open(&treeobj, repo, id);
335 9c70d4c3 2017-11-30 stsp if (err)
336 9c70d4c3 2017-11-30 stsp goto done;
337 9c70d4c3 2017-11-30 stsp
338 15a94983 2018-12-23 stsp if (treeobj->type != GOT_OBJ_TYPE_TREE) {
339 9c70d4c3 2017-11-30 stsp err = got_error(GOT_ERR_OBJ_TYPE);
340 9c70d4c3 2017-11-30 stsp goto done;
341 9c70d4c3 2017-11-30 stsp }
342 9c70d4c3 2017-11-30 stsp
343 9c70d4c3 2017-11-30 stsp err = got_object_tree_open(&tree, repo, treeobj);
344 9c70d4c3 2017-11-30 stsp if (err)
345 9c70d4c3 2017-11-30 stsp goto done;
346 9c70d4c3 2017-11-30 stsp
347 aaa13589 2019-06-01 stsp err = got_diff_tree(NULL, tree, NULL, label, repo, cb, cb_arg);
348 9c70d4c3 2017-11-30 stsp done:
349 9c70d4c3 2017-11-30 stsp if (tree)
350 9c70d4c3 2017-11-30 stsp got_object_tree_close(tree);
351 9c70d4c3 2017-11-30 stsp if (treeobj)
352 9c70d4c3 2017-11-30 stsp got_object_close(treeobj);
353 9c70d4c3 2017-11-30 stsp return err;
354 474b4f94 2017-11-30 stsp }
355 474b4f94 2017-11-30 stsp
356 474b4f94 2017-11-30 stsp static const struct got_error *
357 789689b5 2017-11-30 stsp diff_modified_tree(struct got_object_id *id1, struct got_object_id *id2,
358 aaa13589 2019-06-01 stsp const char *label1, const char *label2, struct got_repository *repo,
359 aaa13589 2019-06-01 stsp got_diff_blob_cb cb, void *cb_arg)
360 474b4f94 2017-11-30 stsp {
361 f6861a81 2018-09-13 stsp const struct got_error *err;
362 789689b5 2017-11-30 stsp struct got_object *treeobj1 = NULL;
363 789689b5 2017-11-30 stsp struct got_object *treeobj2 = NULL;
364 789689b5 2017-11-30 stsp struct got_tree_object *tree1 = NULL;
365 789689b5 2017-11-30 stsp struct got_tree_object *tree2 = NULL;
366 789689b5 2017-11-30 stsp
367 789689b5 2017-11-30 stsp err = got_object_open(&treeobj1, repo, id1);
368 789689b5 2017-11-30 stsp if (err)
369 789689b5 2017-11-30 stsp goto done;
370 789689b5 2017-11-30 stsp
371 15a94983 2018-12-23 stsp if (treeobj1->type != GOT_OBJ_TYPE_TREE) {
372 789689b5 2017-11-30 stsp err = got_error(GOT_ERR_OBJ_TYPE);
373 789689b5 2017-11-30 stsp goto done;
374 789689b5 2017-11-30 stsp }
375 789689b5 2017-11-30 stsp
376 789689b5 2017-11-30 stsp err = got_object_open(&treeobj2, repo, id2);
377 789689b5 2017-11-30 stsp if (err)
378 789689b5 2017-11-30 stsp goto done;
379 789689b5 2017-11-30 stsp
380 15a94983 2018-12-23 stsp if (treeobj2->type != GOT_OBJ_TYPE_TREE) {
381 789689b5 2017-11-30 stsp err = got_error(GOT_ERR_OBJ_TYPE);
382 789689b5 2017-11-30 stsp goto done;
383 789689b5 2017-11-30 stsp }
384 789689b5 2017-11-30 stsp
385 789689b5 2017-11-30 stsp err = got_object_tree_open(&tree1, repo, treeobj1);
386 789689b5 2017-11-30 stsp if (err)
387 789689b5 2017-11-30 stsp goto done;
388 789689b5 2017-11-30 stsp
389 789689b5 2017-11-30 stsp err = got_object_tree_open(&tree2, repo, treeobj2);
390 789689b5 2017-11-30 stsp if (err)
391 789689b5 2017-11-30 stsp goto done;
392 789689b5 2017-11-30 stsp
393 aaa13589 2019-06-01 stsp err = got_diff_tree(tree1, tree2, label1, label2, repo, cb, cb_arg);
394 789689b5 2017-11-30 stsp
395 789689b5 2017-11-30 stsp done:
396 789689b5 2017-11-30 stsp if (tree1)
397 789689b5 2017-11-30 stsp got_object_tree_close(tree1);
398 789689b5 2017-11-30 stsp if (tree2)
399 789689b5 2017-11-30 stsp got_object_tree_close(tree2);
400 789689b5 2017-11-30 stsp if (treeobj1)
401 789689b5 2017-11-30 stsp got_object_close(treeobj1);
402 789689b5 2017-11-30 stsp if (treeobj2)
403 789689b5 2017-11-30 stsp got_object_close(treeobj2);
404 789689b5 2017-11-30 stsp return err;
405 474b4f94 2017-11-30 stsp }
406 474b4f94 2017-11-30 stsp
407 474b4f94 2017-11-30 stsp static const struct got_error *
408 54156555 2018-12-24 stsp diff_deleted_tree(struct got_object_id *id, const char *label,
409 aaa13589 2019-06-01 stsp struct got_repository *repo, got_diff_blob_cb cb, void *cb_arg)
410 474b4f94 2017-11-30 stsp {
411 f6861a81 2018-09-13 stsp const struct got_error *err;
412 2c56f2ce 2017-11-30 stsp struct got_object *treeobj = NULL;
413 2c56f2ce 2017-11-30 stsp struct got_tree_object *tree = NULL;
414 2c56f2ce 2017-11-30 stsp
415 2c56f2ce 2017-11-30 stsp err = got_object_open(&treeobj, repo, id);
416 2c56f2ce 2017-11-30 stsp if (err)
417 2c56f2ce 2017-11-30 stsp goto done;
418 2c56f2ce 2017-11-30 stsp
419 15a94983 2018-12-23 stsp if (treeobj->type != GOT_OBJ_TYPE_TREE) {
420 2c56f2ce 2017-11-30 stsp err = got_error(GOT_ERR_OBJ_TYPE);
421 2c56f2ce 2017-11-30 stsp goto done;
422 2c56f2ce 2017-11-30 stsp }
423 2c56f2ce 2017-11-30 stsp
424 2c56f2ce 2017-11-30 stsp err = got_object_tree_open(&tree, repo, treeobj);
425 2c56f2ce 2017-11-30 stsp if (err)
426 2c56f2ce 2017-11-30 stsp goto done;
427 2c56f2ce 2017-11-30 stsp
428 aaa13589 2019-06-01 stsp err = got_diff_tree(tree, NULL, label, NULL, repo, cb, cb_arg);
429 2c56f2ce 2017-11-30 stsp done:
430 2c56f2ce 2017-11-30 stsp if (tree)
431 2c56f2ce 2017-11-30 stsp got_object_tree_close(tree);
432 2c56f2ce 2017-11-30 stsp if (treeobj)
433 2c56f2ce 2017-11-30 stsp got_object_close(treeobj);
434 2c56f2ce 2017-11-30 stsp return err;
435 474b4f94 2017-11-30 stsp }
436 474b4f94 2017-11-30 stsp
437 474b4f94 2017-11-30 stsp static const struct got_error *
438 74671950 2018-02-11 stsp diff_kind_mismatch(struct got_object_id *id1, struct got_object_id *id2,
439 aaa13589 2019-06-01 stsp const char *label1, const char *label2, struct got_repository *repo,
440 aaa13589 2019-06-01 stsp got_diff_blob_cb cb, void *cb_arg)
441 474b4f94 2017-11-30 stsp {
442 013404a9 2017-11-30 stsp /* XXX TODO */
443 474b4f94 2017-11-30 stsp return NULL;
444 474b4f94 2017-11-30 stsp }
445 474b4f94 2017-11-30 stsp
446 474b4f94 2017-11-30 stsp static const struct got_error *
447 1de5e065 2019-06-01 stsp diff_entry_old_new(const struct got_tree_entry *te1,
448 1de5e065 2019-06-01 stsp const struct got_tree_entry *te2, const char *label1, const char *label2,
449 aaa13589 2019-06-01 stsp struct got_repository *repo, got_diff_blob_cb cb, void *cb_arg)
450 474b4f94 2017-11-30 stsp {
451 f6861a81 2018-09-13 stsp const struct got_error *err = NULL;
452 19ae6da1 2018-11-05 stsp int id_match;
453 474b4f94 2017-11-30 stsp
454 474b4f94 2017-11-30 stsp if (te2 == NULL) {
455 474b4f94 2017-11-30 stsp if (S_ISDIR(te1->mode))
456 aaa13589 2019-06-01 stsp err = diff_deleted_tree(te1->id, label1, repo,
457 aaa13589 2019-06-01 stsp cb, cb_arg);
458 f6861a81 2018-09-13 stsp else
459 aaa13589 2019-06-01 stsp err = diff_deleted_blob(te1->id, label1, repo,
460 aaa13589 2019-06-01 stsp cb, cb_arg);
461 f6861a81 2018-09-13 stsp return err;
462 474b4f94 2017-11-30 stsp }
463 474b4f94 2017-11-30 stsp
464 19ae6da1 2018-11-05 stsp id_match = (got_object_id_cmp(te1->id, te2->id) == 0);
465 4209f790 2017-11-30 stsp if (S_ISDIR(te1->mode) && S_ISDIR(te2->mode)) {
466 19ae6da1 2018-11-05 stsp if (!id_match)
467 f6861a81 2018-09-13 stsp return diff_modified_tree(te1->id, te2->id,
468 aaa13589 2019-06-01 stsp label1, label2, repo, cb, cb_arg);
469 4209f790 2017-11-30 stsp } else if (S_ISREG(te1->mode) && S_ISREG(te2->mode)) {
470 19ae6da1 2018-11-05 stsp if (!id_match)
471 f6861a81 2018-09-13 stsp return diff_modified_blob(te1->id, te2->id,
472 aaa13589 2019-06-01 stsp label1, label2, repo, cb, cb_arg);
473 413ea19d 2017-11-30 stsp }
474 474b4f94 2017-11-30 stsp
475 19ae6da1 2018-11-05 stsp if (id_match)
476 f6861a81 2018-09-13 stsp return NULL;
477 f6861a81 2018-09-13 stsp
478 aaa13589 2019-06-01 stsp return diff_kind_mismatch(te1->id, te2->id, label1, label2, repo,
479 aaa13589 2019-06-01 stsp cb, cb_arg);
480 474b4f94 2017-11-30 stsp }
481 474b4f94 2017-11-30 stsp
482 474b4f94 2017-11-30 stsp static const struct got_error *
483 1de5e065 2019-06-01 stsp diff_entry_new_old(const struct got_tree_entry *te2,
484 aaa13589 2019-06-01 stsp const struct got_tree_entry *te1, const char *label2,
485 aaa13589 2019-06-01 stsp struct got_repository *repo, got_diff_blob_cb cb, void *cb_arg)
486 474b4f94 2017-11-30 stsp {
487 f6861a81 2018-09-13 stsp if (te1 != NULL) /* handled by diff_entry_old_new() */
488 f6861a81 2018-09-13 stsp return NULL;
489 474b4f94 2017-11-30 stsp
490 474b4f94 2017-11-30 stsp if (S_ISDIR(te2->mode))
491 aaa13589 2019-06-01 stsp return diff_added_tree(te2->id, label2, repo, cb, cb_arg);
492 f6861a81 2018-09-13 stsp
493 aaa13589 2019-06-01 stsp return diff_added_blob(te2->id, label2, repo, cb, cb_arg);
494 474b4f94 2017-11-30 stsp }
495 474b4f94 2017-11-30 stsp
496 474b4f94 2017-11-30 stsp const struct got_error *
497 474b4f94 2017-11-30 stsp got_diff_tree(struct got_tree_object *tree1, struct got_tree_object *tree2,
498 aaa13589 2019-06-01 stsp const char *label1, const char *label2, struct got_repository *repo,
499 aaa13589 2019-06-01 stsp got_diff_blob_cb cb, void *cb_arg)
500 474b4f94 2017-11-30 stsp {
501 474b4f94 2017-11-30 stsp const struct got_error *err = NULL;
502 789689b5 2017-11-30 stsp struct got_tree_entry *te1 = NULL;
503 789689b5 2017-11-30 stsp struct got_tree_entry *te2 = NULL;
504 f6861a81 2018-09-13 stsp char *l1 = NULL, *l2 = NULL;
505 474b4f94 2017-11-30 stsp
506 883f0469 2018-06-23 stsp if (tree1) {
507 883f0469 2018-06-23 stsp const struct got_tree_entries *entries;
508 883f0469 2018-06-23 stsp entries = got_object_tree_get_entries(tree1);
509 883f0469 2018-06-23 stsp te1 = SIMPLEQ_FIRST(&entries->head);
510 60f50a58 2018-09-15 stsp if (te1 && asprintf(&l1, "%s%s%s", label1, label1[0] ? "/" : "",
511 f6861a81 2018-09-13 stsp te1->name) == -1)
512 638f9024 2019-05-13 stsp return got_error_from_errno("asprintf");
513 883f0469 2018-06-23 stsp }
514 883f0469 2018-06-23 stsp if (tree2) {
515 883f0469 2018-06-23 stsp const struct got_tree_entries *entries;
516 883f0469 2018-06-23 stsp entries = got_object_tree_get_entries(tree2);
517 883f0469 2018-06-23 stsp te2 = SIMPLEQ_FIRST(&entries->head);
518 60f50a58 2018-09-15 stsp if (te2 && asprintf(&l2, "%s%s%s", label2, label2[0] ? "/" : "",
519 f6861a81 2018-09-13 stsp te2->name) == -1)
520 638f9024 2019-05-13 stsp return got_error_from_errno("asprintf");
521 883f0469 2018-06-23 stsp }
522 474b4f94 2017-11-30 stsp
523 474b4f94 2017-11-30 stsp do {
524 474b4f94 2017-11-30 stsp if (te1) {
525 1de5e065 2019-06-01 stsp const struct got_tree_entry *te = NULL;
526 f6861a81 2018-09-13 stsp if (tree2)
527 1de5e065 2019-06-01 stsp te = got_object_tree_find_entry(tree2,
528 1de5e065 2019-06-01 stsp te1->name);
529 f6861a81 2018-09-13 stsp if (te) {
530 f6861a81 2018-09-13 stsp free(l2);
531 f6861a81 2018-09-13 stsp l2 = NULL;
532 f6861a81 2018-09-13 stsp if (te && asprintf(&l2, "%s%s%s", label2,
533 f6861a81 2018-09-13 stsp label2[0] ? "/" : "", te->name) == -1)
534 230a42bd 2019-05-11 jcs return
535 638f9024 2019-05-13 stsp got_error_from_errno("asprintf");
536 f6861a81 2018-09-13 stsp }
537 aaa13589 2019-06-01 stsp err = diff_entry_old_new(te1, te, l1, l2, repo, cb,
538 aaa13589 2019-06-01 stsp cb_arg);
539 474b4f94 2017-11-30 stsp if (err)
540 474b4f94 2017-11-30 stsp break;
541 474b4f94 2017-11-30 stsp }
542 474b4f94 2017-11-30 stsp
543 474b4f94 2017-11-30 stsp if (te2) {
544 1de5e065 2019-06-01 stsp const struct got_tree_entry *te = NULL;
545 f6861a81 2018-09-13 stsp if (tree1)
546 1de5e065 2019-06-01 stsp te = got_object_tree_find_entry(tree1,
547 1de5e065 2019-06-01 stsp te2->name);
548 d6ce02f1 2018-11-17 stsp free(l2);
549 d6ce02f1 2018-11-17 stsp if (te) {
550 d6ce02f1 2018-11-17 stsp if (asprintf(&l2, "%s%s%s", label2,
551 d6ce02f1 2018-11-17 stsp label2[0] ? "/" : "", te->name) == -1)
552 230a42bd 2019-05-11 jcs return
553 638f9024 2019-05-13 stsp got_error_from_errno("asprintf");
554 d6ce02f1 2018-11-17 stsp } else {
555 d6ce02f1 2018-11-17 stsp if (asprintf(&l2, "%s%s%s", label2,
556 d6ce02f1 2018-11-17 stsp label2[0] ? "/" : "", te2->name) == -1)
557 230a42bd 2019-05-11 jcs return
558 638f9024 2019-05-13 stsp got_error_from_errno("asprintf");
559 d6ce02f1 2018-11-17 stsp }
560 aaa13589 2019-06-01 stsp err = diff_entry_new_old(te2, te, l2, repo, cb, cb_arg);
561 474b4f94 2017-11-30 stsp if (err)
562 474b4f94 2017-11-30 stsp break;
563 474b4f94 2017-11-30 stsp }
564 474b4f94 2017-11-30 stsp
565 f6861a81 2018-09-13 stsp free(l1);
566 f6861a81 2018-09-13 stsp l1 = NULL;
567 f6861a81 2018-09-13 stsp if (te1) {
568 474b4f94 2017-11-30 stsp te1 = SIMPLEQ_NEXT(te1, entry);
569 f6861a81 2018-09-13 stsp if (te1 &&
570 f6861a81 2018-09-13 stsp asprintf(&l1, "%s%s%s", label1,
571 f6861a81 2018-09-13 stsp label1[0] ? "/" : "", te1->name) == -1)
572 638f9024 2019-05-13 stsp return got_error_from_errno("asprintf");
573 f6861a81 2018-09-13 stsp }
574 f6861a81 2018-09-13 stsp free(l2);
575 f6861a81 2018-09-13 stsp l2 = NULL;
576 f6861a81 2018-09-13 stsp if (te2) {
577 474b4f94 2017-11-30 stsp te2 = SIMPLEQ_NEXT(te2, entry);
578 f6861a81 2018-09-13 stsp if (te2 &&
579 f6861a81 2018-09-13 stsp asprintf(&l2, "%s%s%s", label2,
580 f6861a81 2018-09-13 stsp label2[0] ? "/" : "", te2->name) == -1)
581 638f9024 2019-05-13 stsp return got_error_from_errno("asprintf");
582 f6861a81 2018-09-13 stsp }
583 474b4f94 2017-11-30 stsp } while (te1 || te2);
584 11528a82 2018-05-19 stsp
585 11528a82 2018-05-19 stsp return err;
586 11528a82 2018-05-19 stsp }
587 11528a82 2018-05-19 stsp
588 11528a82 2018-05-19 stsp const struct got_error *
589 15a94983 2018-12-23 stsp got_diff_objects_as_blobs(struct got_object_id *id1, struct got_object_id *id2,
590 54156555 2018-12-24 stsp const char *label1, const char *label2, int diff_context,
591 54156555 2018-12-24 stsp struct got_repository *repo, FILE *outfile)
592 11528a82 2018-05-19 stsp {
593 11528a82 2018-05-19 stsp const struct got_error *err;
594 11528a82 2018-05-19 stsp struct got_blob_object *blob1 = NULL, *blob2 = NULL;
595 b74c7625 2018-05-20 stsp
596 15a94983 2018-12-23 stsp if (id1 == NULL && id2 == NULL)
597 b74c7625 2018-05-20 stsp return got_error(GOT_ERR_NO_OBJ);
598 11528a82 2018-05-19 stsp
599 15a94983 2018-12-23 stsp if (id1) {
600 15a94983 2018-12-23 stsp err = got_object_open_as_blob(&blob1, repo, id1, 8192);
601 cd0acaa7 2018-05-20 stsp if (err)
602 cd0acaa7 2018-05-20 stsp goto done;
603 cd0acaa7 2018-05-20 stsp }
604 15a94983 2018-12-23 stsp if (id2) {
605 15a94983 2018-12-23 stsp err = got_object_open_as_blob(&blob2, repo, id2, 8192);
606 cd0acaa7 2018-05-20 stsp if (err)
607 cd0acaa7 2018-05-20 stsp goto done;
608 cd0acaa7 2018-05-20 stsp }
609 54156555 2018-12-24 stsp err = got_diff_blob(blob1, blob2, label1, label2, diff_context,
610 54156555 2018-12-24 stsp outfile);
611 11528a82 2018-05-19 stsp done:
612 11528a82 2018-05-19 stsp if (blob1)
613 11528a82 2018-05-19 stsp got_object_blob_close(blob1);
614 11528a82 2018-05-19 stsp if (blob2)
615 11528a82 2018-05-19 stsp got_object_blob_close(blob2);
616 474b4f94 2017-11-30 stsp return err;
617 474b4f94 2017-11-30 stsp }
618 11528a82 2018-05-19 stsp
619 11528a82 2018-05-19 stsp const struct got_error *
620 15a94983 2018-12-23 stsp got_diff_objects_as_trees(struct got_object_id *id1, struct got_object_id *id2,
621 54156555 2018-12-24 stsp char *label1, char *label2, int diff_context, struct got_repository *repo,
622 54156555 2018-12-24 stsp FILE *outfile)
623 11528a82 2018-05-19 stsp {
624 11528a82 2018-05-19 stsp const struct got_error *err;
625 11528a82 2018-05-19 stsp struct got_tree_object *tree1 = NULL, *tree2 = NULL;
626 aaa13589 2019-06-01 stsp struct got_diff_blob_output_unidiff_arg arg;
627 11528a82 2018-05-19 stsp
628 15a94983 2018-12-23 stsp if (id1 == NULL && id2 == NULL)
629 b74c7625 2018-05-20 stsp return got_error(GOT_ERR_NO_OBJ);
630 b74c7625 2018-05-20 stsp
631 15a94983 2018-12-23 stsp if (id1) {
632 15a94983 2018-12-23 stsp err = got_object_open_as_tree(&tree1, repo, id1);
633 cd0acaa7 2018-05-20 stsp if (err)
634 cd0acaa7 2018-05-20 stsp goto done;
635 cd0acaa7 2018-05-20 stsp }
636 15a94983 2018-12-23 stsp if (id2) {
637 15a94983 2018-12-23 stsp err = got_object_open_as_tree(&tree2, repo, id2);
638 cd0acaa7 2018-05-20 stsp if (err)
639 cd0acaa7 2018-05-20 stsp goto done;
640 cd0acaa7 2018-05-20 stsp }
641 aaa13589 2019-06-01 stsp arg.diff_context = diff_context;
642 aaa13589 2019-06-01 stsp arg.outfile = outfile;
643 aaa13589 2019-06-01 stsp err = got_diff_tree(tree1, tree2, label1, label2, repo,
644 aaa13589 2019-06-01 stsp got_diff_blob_output_unidiff, &arg);
645 11528a82 2018-05-19 stsp done:
646 11528a82 2018-05-19 stsp if (tree1)
647 11528a82 2018-05-19 stsp got_object_tree_close(tree1);
648 11528a82 2018-05-19 stsp if (tree2)
649 11528a82 2018-05-19 stsp got_object_tree_close(tree2);
650 11528a82 2018-05-19 stsp return err;
651 11528a82 2018-05-19 stsp }
652 11528a82 2018-05-19 stsp
653 11528a82 2018-05-19 stsp const struct got_error *
654 15a94983 2018-12-23 stsp got_diff_objects_as_commits(struct got_object_id *id1,
655 15a94983 2018-12-23 stsp struct got_object_id *id2, int diff_context,
656 15a94983 2018-12-23 stsp struct got_repository *repo, FILE *outfile)
657 11528a82 2018-05-19 stsp {
658 11528a82 2018-05-19 stsp const struct got_error *err;
659 11528a82 2018-05-19 stsp struct got_commit_object *commit1 = NULL, *commit2 = NULL;
660 11528a82 2018-05-19 stsp
661 15a94983 2018-12-23 stsp if (id2 == NULL)
662 b74c7625 2018-05-20 stsp return got_error(GOT_ERR_NO_OBJ);
663 b74c7625 2018-05-20 stsp
664 15a94983 2018-12-23 stsp if (id1) {
665 15a94983 2018-12-23 stsp err = got_object_open_as_commit(&commit1, repo, id1);
666 cd0acaa7 2018-05-20 stsp if (err)
667 cd0acaa7 2018-05-20 stsp goto done;
668 cd0acaa7 2018-05-20 stsp }
669 bacc9935 2018-05-20 stsp
670 15a94983 2018-12-23 stsp err = got_object_open_as_commit(&commit2, repo, id2);
671 9b697879 2018-05-20 stsp if (err)
672 9b697879 2018-05-20 stsp goto done;
673 9b697879 2018-05-20 stsp
674 15a94983 2018-12-23 stsp err = got_diff_objects_as_trees(
675 15a94983 2018-12-23 stsp commit1 ? got_object_commit_get_tree_id(commit1) : NULL,
676 54156555 2018-12-24 stsp got_object_commit_get_tree_id(commit2), "", "", diff_context, repo,
677 54156555 2018-12-24 stsp outfile);
678 11528a82 2018-05-19 stsp done:
679 11528a82 2018-05-19 stsp if (commit1)
680 11528a82 2018-05-19 stsp got_object_commit_close(commit1);
681 11528a82 2018-05-19 stsp if (commit2)
682 11528a82 2018-05-19 stsp got_object_commit_close(commit2);
683 11528a82 2018-05-19 stsp return err;
684 11528a82 2018-05-19 stsp }