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