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