2 7d283eee 2017-11-29 stsp * Copyright (c) 2017 Stefan Sperling <stsp@openbsd.org>
4 7d283eee 2017-11-29 stsp * Permission to use, copy, modify, and distribute this software for any
5 7d283eee 2017-11-29 stsp * purpose with or without fee is hereby granted, provided that the above
6 7d283eee 2017-11-29 stsp * copyright notice and this permission notice appear in all copies.
8 7d283eee 2017-11-29 stsp * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 7d283eee 2017-11-29 stsp * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 7d283eee 2017-11-29 stsp * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 7d283eee 2017-11-29 stsp * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 7d283eee 2017-11-29 stsp * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 7d283eee 2017-11-29 stsp * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 7d283eee 2017-11-29 stsp * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 7d283eee 2017-11-29 stsp #include <sys/queue.h>
18 1c7f0520 2017-11-29 stsp #include <sys/stat.h>
20 7d283eee 2017-11-29 stsp #include <stdio.h>
21 7d283eee 2017-11-29 stsp #include <stdlib.h>
22 7d283eee 2017-11-29 stsp #include <string.h>
23 f9d67749 2017-11-30 stsp #include <limits.h>
24 7d283eee 2017-11-29 stsp #include <sha1.h>
25 7d283eee 2017-11-29 stsp #include <zlib.h>
27 7d283eee 2017-11-29 stsp #include "got_repository.h"
28 7d283eee 2017-11-29 stsp #include "got_object.h"
29 7d283eee 2017-11-29 stsp #include "got_error.h"
30 789689b5 2017-11-30 stsp #include "got_diff.h"
31 511a516b 2018-05-19 stsp #include "got_opentemp.h"
33 718b3ab0 2018-03-17 stsp #include "got_lib_diff.h"
34 718b3ab0 2018-03-17 stsp #include "got_lib_path.h"
36 7d283eee 2017-11-29 stsp const struct got_error *
37 7d283eee 2017-11-29 stsp got_diff_blob(struct got_blob_object *blob1, struct got_blob_object *blob2,
38 474b4f94 2017-11-30 stsp const char *label1, const char *label2, FILE *outfile)
40 ed9e98a8 2017-11-29 stsp struct got_diff_state ds;
41 8ba9a219 2017-11-29 stsp struct got_diff_args args;
42 7d283eee 2017-11-29 stsp const struct got_error *err = NULL;
43 4e22badc 2017-11-30 stsp FILE *f1 = NULL, *f2 = NULL;
44 f78b0693 2017-11-29 stsp char hex1[SHA1_DIGEST_STRING_LENGTH];
45 f78b0693 2017-11-29 stsp char hex2[SHA1_DIGEST_STRING_LENGTH];
46 98abbc84 2017-11-30 stsp char *idstr1 = NULL, *idstr2 = NULL;
47 f934cf2c 2018-02-12 stsp size_t size1, size2;
48 4e22badc 2017-11-30 stsp int res, flags = 0;
50 4e22badc 2017-11-30 stsp if (blob1) {
51 a1fd68d8 2018-01-12 stsp f1 = got_opentemp();
52 4e22badc 2017-11-30 stsp if (f1 == NULL)
53 4e22badc 2017-11-30 stsp return got_error(GOT_ERR_FILE_OPEN);
55 4e22badc 2017-11-30 stsp flags |= D_EMPTY1;
57 4e22badc 2017-11-30 stsp if (blob2) {
58 a1fd68d8 2018-01-12 stsp f2 = got_opentemp();
59 4e22badc 2017-11-30 stsp if (f2 == NULL) {
61 4e22badc 2017-11-30 stsp return got_error(GOT_ERR_FILE_OPEN);
64 4e22badc 2017-11-30 stsp flags |= D_EMPTY2;
67 98abbc84 2017-11-30 stsp if (blob1) {
68 f934cf2c 2018-02-12 stsp idstr1 = got_object_blob_id_str(blob1, hex1, sizeof(hex1));
69 35e9ba5d 2018-06-21 stsp err = got_object_blob_dump_to_file(&size1, f1, blob1);
73 98abbc84 2017-11-30 stsp idstr1 = "/dev/null";
76 98abbc84 2017-11-30 stsp if (blob2) {
77 f934cf2c 2018-02-12 stsp idstr2 = got_object_blob_id_str(blob2, hex2, sizeof(hex2));
78 35e9ba5d 2018-06-21 stsp err = got_object_blob_dump_to_file(&size2, f2, blob2);
82 98abbc84 2017-11-30 stsp idstr2 = "/dev/null";
84 ed9e98a8 2017-11-29 stsp memset(&ds, 0, sizeof(ds));
85 f9d67749 2017-11-30 stsp /* XXX should stat buffers be passed in args instead of ds? */
86 f9d67749 2017-11-30 stsp ds.stb1.st_mode = S_IFREG;
88 f934cf2c 2018-02-12 stsp ds.stb1.st_size = size1;
89 f9d67749 2017-11-30 stsp ds.stb1.st_mtime = 0; /* XXX */
91 f9d67749 2017-11-30 stsp ds.stb2.st_mode = S_IFREG;
93 f934cf2c 2018-02-12 stsp ds.stb2.st_size = size2;
94 f9d67749 2017-11-30 stsp ds.stb2.st_mtime = 0; /* XXX */
96 f9d67749 2017-11-30 stsp memset(&args, 0, sizeof(args));
97 8ba9a219 2017-11-29 stsp args.diff_format = D_UNIFIED;
98 98abbc84 2017-11-30 stsp args.label[0] = label1 ? label1 : idstr1;
99 98abbc84 2017-11-30 stsp args.label[1] = label2 ? label2 : idstr2;
100 c2c21d46 2018-03-27 stsp args.diff_context = 3;
101 84eb021e 2018-03-27 stsp flags |= D_PROTOTYPE;
103 cb74ff21 2017-11-30 stsp err = got_diffreg(&res, f1, f2, flags, &args, &ds, outfile);
106 98abbc84 2017-11-30 stsp fclose(f1);
108 98abbc84 2017-11-30 stsp fclose(f2);
109 7d283eee 2017-11-29 stsp return err;
112 a3e2cbea 2017-12-01 stsp struct got_tree_entry *
113 a3e2cbea 2017-12-01 stsp match_entry_by_name(struct got_tree_entry *te1, struct got_tree_object *tree2)
115 a3e2cbea 2017-12-01 stsp struct got_tree_entry *te2;
117 a3e2cbea 2017-12-01 stsp SIMPLEQ_FOREACH(te2, &tree2->entries, entry) {
118 a3e2cbea 2017-12-01 stsp if (strcmp(te1->name, te2->name) == 0)
119 a3e2cbea 2017-12-01 stsp return te2;
121 474b4f94 2017-11-30 stsp return NULL;
124 474b4f94 2017-11-30 stsp static const struct got_error *
125 74671950 2018-02-11 stsp diff_added_blob(struct got_object_id *id, struct got_repository *repo,
126 74671950 2018-02-11 stsp FILE *outfile)
128 4e22badc 2017-11-30 stsp const struct got_error *err;
129 2acfca77 2018-04-01 stsp struct got_blob_object *blob = NULL;
130 2acfca77 2018-04-01 stsp struct got_object *obj = NULL;
132 4e22badc 2017-11-30 stsp err = got_object_open(&obj, repo, id);
134 4e22badc 2017-11-30 stsp return err;
136 2acfca77 2018-04-01 stsp err = got_object_blob_open(&blob, repo, obj, 8192);
139 2acfca77 2018-04-01 stsp err = got_diff_blob(NULL, blob, NULL, NULL, outfile);
141 2acfca77 2018-04-01 stsp got_object_close(obj);
143 2acfca77 2018-04-01 stsp got_object_blob_close(blob);
144 2acfca77 2018-04-01 stsp return err;
147 474b4f94 2017-11-30 stsp static const struct got_error *
148 6a213ccb 2017-11-30 stsp diff_modified_blob(struct got_object_id *id1, struct got_object_id *id2,
149 74671950 2018-02-11 stsp struct got_repository *repo, FILE *outfile)
151 6a213ccb 2017-11-30 stsp const struct got_error *err;
152 6a213ccb 2017-11-30 stsp struct got_object *obj1 = NULL;
153 6a213ccb 2017-11-30 stsp struct got_object *obj2 = NULL;
154 6a213ccb 2017-11-30 stsp struct got_blob_object *blob1 = NULL;
155 6a213ccb 2017-11-30 stsp struct got_blob_object *blob2 = NULL;
157 6a213ccb 2017-11-30 stsp err = got_object_open(&obj1, repo, id1);
159 730a8aa0 2018-04-24 stsp return err;
160 eef6493a 2018-01-19 stsp if (got_object_get_type(obj1) != GOT_OBJ_TYPE_BLOB) {
161 6a213ccb 2017-11-30 stsp err = got_error(GOT_ERR_OBJ_TYPE);
165 6a213ccb 2017-11-30 stsp err = got_object_open(&obj2, repo, id2);
168 eef6493a 2018-01-19 stsp if (got_object_get_type(obj2) != GOT_OBJ_TYPE_BLOB) {
169 6a213ccb 2017-11-30 stsp err = got_error(GOT_ERR_BAD_OBJ_DATA);
173 c7020aea 2017-11-30 stsp err = got_object_blob_open(&blob1, repo, obj1, 8192);
177 c7020aea 2017-11-30 stsp err = got_object_blob_open(&blob2, repo, obj2, 8192);
181 74671950 2018-02-11 stsp err = got_diff_blob(blob1, blob2, NULL, NULL, outfile);
185 a3e2cbea 2017-12-01 stsp got_object_close(obj1);
187 a3e2cbea 2017-12-01 stsp got_object_close(obj2);
189 a3e2cbea 2017-12-01 stsp got_object_blob_close(blob1);
191 a3e2cbea 2017-12-01 stsp got_object_blob_close(blob2);
192 6a213ccb 2017-11-30 stsp return err;
195 474b4f94 2017-11-30 stsp static const struct got_error *
196 74671950 2018-02-11 stsp diff_deleted_blob(struct got_object_id *id, struct got_repository *repo,
197 74671950 2018-02-11 stsp FILE *outfile)
199 365fb436 2017-11-30 stsp const struct got_error *err;
200 2acfca77 2018-04-01 stsp struct got_blob_object *blob = NULL;
201 2acfca77 2018-04-01 stsp struct got_object *obj = NULL;
203 365fb436 2017-11-30 stsp err = got_object_open(&obj, repo, id);
205 365fb436 2017-11-30 stsp return err;
207 2acfca77 2018-04-01 stsp err = got_object_blob_open(&blob, repo, obj, 8192);
210 2acfca77 2018-04-01 stsp err = got_diff_blob(blob, NULL, NULL, NULL, outfile);
212 2acfca77 2018-04-01 stsp got_object_close(obj);
214 2acfca77 2018-04-01 stsp got_object_blob_close(blob);
215 2acfca77 2018-04-01 stsp return err;
218 474b4f94 2017-11-30 stsp static const struct got_error *
219 74671950 2018-02-11 stsp diff_added_tree(struct got_object_id *id, struct got_repository *repo,
220 74671950 2018-02-11 stsp FILE *outfile)
222 9c70d4c3 2017-11-30 stsp const struct got_error *err = NULL;
223 9c70d4c3 2017-11-30 stsp struct got_object *treeobj = NULL;
224 9c70d4c3 2017-11-30 stsp struct got_tree_object *tree = NULL;
226 9c70d4c3 2017-11-30 stsp err = got_object_open(&treeobj, repo, id);
230 b107e67f 2018-01-19 stsp if (got_object_get_type(treeobj) != GOT_OBJ_TYPE_TREE) {
231 9c70d4c3 2017-11-30 stsp err = got_error(GOT_ERR_OBJ_TYPE);
235 9c70d4c3 2017-11-30 stsp err = got_object_tree_open(&tree, repo, treeobj);
239 74671950 2018-02-11 stsp err = got_diff_tree(NULL, tree, repo, outfile);
243 9c70d4c3 2017-11-30 stsp got_object_tree_close(tree);
244 9c70d4c3 2017-11-30 stsp if (treeobj)
245 9c70d4c3 2017-11-30 stsp got_object_close(treeobj);
246 9c70d4c3 2017-11-30 stsp return err;
249 474b4f94 2017-11-30 stsp static const struct got_error *
250 789689b5 2017-11-30 stsp diff_modified_tree(struct got_object_id *id1, struct got_object_id *id2,
251 74671950 2018-02-11 stsp struct got_repository *repo, FILE *outfile)
253 789689b5 2017-11-30 stsp const struct got_error *err = NULL;
254 789689b5 2017-11-30 stsp struct got_object *treeobj1 = NULL;
255 789689b5 2017-11-30 stsp struct got_object *treeobj2 = NULL;
256 789689b5 2017-11-30 stsp struct got_tree_object *tree1 = NULL;
257 789689b5 2017-11-30 stsp struct got_tree_object *tree2 = NULL;
259 789689b5 2017-11-30 stsp err = got_object_open(&treeobj1, repo, id1);
263 eef6493a 2018-01-19 stsp if (got_object_get_type(treeobj1) != GOT_OBJ_TYPE_TREE) {
264 789689b5 2017-11-30 stsp err = got_error(GOT_ERR_OBJ_TYPE);
268 789689b5 2017-11-30 stsp err = got_object_open(&treeobj2, repo, id2);
272 eef6493a 2018-01-19 stsp if (got_object_get_type(treeobj2) != GOT_OBJ_TYPE_TREE) {
273 789689b5 2017-11-30 stsp err = got_error(GOT_ERR_OBJ_TYPE);
277 789689b5 2017-11-30 stsp err = got_object_tree_open(&tree1, repo, treeobj1);
281 789689b5 2017-11-30 stsp err = got_object_tree_open(&tree2, repo, treeobj2);
285 74671950 2018-02-11 stsp err = got_diff_tree(tree1, tree2, repo, outfile);
289 789689b5 2017-11-30 stsp got_object_tree_close(tree1);
291 789689b5 2017-11-30 stsp got_object_tree_close(tree2);
292 789689b5 2017-11-30 stsp if (treeobj1)
293 789689b5 2017-11-30 stsp got_object_close(treeobj1);
294 789689b5 2017-11-30 stsp if (treeobj2)
295 789689b5 2017-11-30 stsp got_object_close(treeobj2);
296 789689b5 2017-11-30 stsp return err;
299 474b4f94 2017-11-30 stsp static const struct got_error *
300 74671950 2018-02-11 stsp diff_deleted_tree(struct got_object_id *id, struct got_repository *repo, FILE *outfile)
302 2c56f2ce 2017-11-30 stsp const struct got_error *err = NULL;
303 2c56f2ce 2017-11-30 stsp struct got_object *treeobj = NULL;
304 2c56f2ce 2017-11-30 stsp struct got_tree_object *tree = NULL;
306 2c56f2ce 2017-11-30 stsp err = got_object_open(&treeobj, repo, id);
310 b107e67f 2018-01-19 stsp if (got_object_get_type(treeobj) != GOT_OBJ_TYPE_TREE) {
311 2c56f2ce 2017-11-30 stsp err = got_error(GOT_ERR_OBJ_TYPE);
315 2c56f2ce 2017-11-30 stsp err = got_object_tree_open(&tree, repo, treeobj);
319 74671950 2018-02-11 stsp err = got_diff_tree(tree, NULL, repo, outfile);
323 2c56f2ce 2017-11-30 stsp got_object_tree_close(tree);
324 2c56f2ce 2017-11-30 stsp if (treeobj)
325 2c56f2ce 2017-11-30 stsp got_object_close(treeobj);
326 2c56f2ce 2017-11-30 stsp return err;
329 474b4f94 2017-11-30 stsp static const struct got_error *
330 74671950 2018-02-11 stsp diff_kind_mismatch(struct got_object_id *id1, struct got_object_id *id2,
331 74671950 2018-02-11 stsp FILE *outfile)
333 013404a9 2017-11-30 stsp /* XXX TODO */
334 474b4f94 2017-11-30 stsp return NULL;
337 474b4f94 2017-11-30 stsp static const struct got_error *
338 6a213ccb 2017-11-30 stsp diff_entry_old_new(struct got_tree_entry *te1, struct got_tree_object *tree2,
339 74671950 2018-02-11 stsp struct got_repository *repo, FILE *outfile)
341 07ccb00b 2018-03-27 stsp struct got_tree_entry *te2 = NULL;
344 07ccb00b 2018-03-27 stsp te2 = match_entry_by_name(te1, tree2);
345 474b4f94 2017-11-30 stsp if (te2 == NULL) {
346 474b4f94 2017-11-30 stsp if (S_ISDIR(te1->mode))
347 59ece79d 2018-02-12 stsp return diff_deleted_tree(te1->id, repo, outfile);
348 59ece79d 2018-02-12 stsp return diff_deleted_blob(te1->id, repo, outfile);
351 4209f790 2017-11-30 stsp if (S_ISDIR(te1->mode) && S_ISDIR(te2->mode)) {
352 59ece79d 2018-02-12 stsp if (got_object_id_cmp(te1->id, te2->id) != 0)
353 59ece79d 2018-02-12 stsp return diff_modified_tree(te1->id, te2->id, repo,
355 4209f790 2017-11-30 stsp } else if (S_ISREG(te1->mode) && S_ISREG(te2->mode)) {
356 59ece79d 2018-02-12 stsp if (got_object_id_cmp(te1->id, te2->id) != 0)
357 59ece79d 2018-02-12 stsp return diff_modified_blob(te1->id, te2->id, repo,
361 59ece79d 2018-02-12 stsp return diff_kind_mismatch(te1->id, te2->id, outfile);
364 474b4f94 2017-11-30 stsp static const struct got_error *
365 4e22badc 2017-11-30 stsp diff_entry_new_old(struct got_tree_entry *te2, struct got_tree_object *tree1,
366 74671950 2018-02-11 stsp struct got_repository *repo, FILE *outfile)
368 07ccb00b 2018-03-27 stsp if (tree1) {
369 07ccb00b 2018-03-27 stsp struct got_tree_entry *te1 = match_entry_by_name(te2, tree1);
370 07ccb00b 2018-03-27 stsp if (te1 != NULL) /* handled by diff_entry_old_new() */
371 07ccb00b 2018-03-27 stsp return NULL;
374 474b4f94 2017-11-30 stsp if (S_ISDIR(te2->mode))
375 59ece79d 2018-02-12 stsp return diff_added_tree(te2->id, repo, outfile);
376 59ece79d 2018-02-12 stsp return diff_added_blob(te2->id, repo, outfile);
379 474b4f94 2017-11-30 stsp const struct got_error *
380 474b4f94 2017-11-30 stsp got_diff_tree(struct got_tree_object *tree1, struct got_tree_object *tree2,
381 74671950 2018-02-11 stsp struct got_repository *repo, FILE *outfile)
383 474b4f94 2017-11-30 stsp const struct got_error *err = NULL;
384 789689b5 2017-11-30 stsp struct got_tree_entry *te1 = NULL;
385 789689b5 2017-11-30 stsp struct got_tree_entry *te2 = NULL;
388 789689b5 2017-11-30 stsp te1 = SIMPLEQ_FIRST(&tree1->entries);
390 789689b5 2017-11-30 stsp te2 = SIMPLEQ_FIRST(&tree2->entries);
394 74671950 2018-02-11 stsp err = diff_entry_old_new(te1, tree2, repo, outfile);
400 74671950 2018-02-11 stsp err = diff_entry_new_old(te2, tree1, repo, outfile);
406 474b4f94 2017-11-30 stsp te1 = SIMPLEQ_NEXT(te1, entry);
408 474b4f94 2017-11-30 stsp te2 = SIMPLEQ_NEXT(te2, entry);
409 474b4f94 2017-11-30 stsp } while (te1 || te2);
411 11528a82 2018-05-19 stsp return err;
414 11528a82 2018-05-19 stsp const struct got_error *
415 11528a82 2018-05-19 stsp got_diff_objects_as_blobs(struct got_object *obj1, struct got_object *obj2,
416 11528a82 2018-05-19 stsp struct got_repository *repo, FILE *outfile)
418 11528a82 2018-05-19 stsp const struct got_error *err;
419 11528a82 2018-05-19 stsp struct got_blob_object *blob1 = NULL, *blob2 = NULL;
421 b74c7625 2018-05-20 stsp if (obj1 == NULL && obj2 == NULL)
422 b74c7625 2018-05-20 stsp return got_error(GOT_ERR_NO_OBJ);
424 cd0acaa7 2018-05-20 stsp if (obj1) {
425 cd0acaa7 2018-05-20 stsp err = got_object_blob_open(&blob1, repo, obj1, 8192);
429 cd0acaa7 2018-05-20 stsp if (obj2) {
430 cd0acaa7 2018-05-20 stsp err = got_object_blob_open(&blob2, repo, obj2, 8192);
434 11528a82 2018-05-19 stsp err = got_diff_blob(blob1, blob2, NULL, NULL, outfile);
437 11528a82 2018-05-19 stsp got_object_blob_close(blob1);
439 11528a82 2018-05-19 stsp got_object_blob_close(blob2);
440 474b4f94 2017-11-30 stsp return err;
443 11528a82 2018-05-19 stsp const struct got_error *
444 11528a82 2018-05-19 stsp got_diff_objects_as_trees(struct got_object *obj1, struct got_object *obj2,
445 11528a82 2018-05-19 stsp struct got_repository *repo, FILE *outfile)
447 11528a82 2018-05-19 stsp const struct got_error *err;
448 11528a82 2018-05-19 stsp struct got_tree_object *tree1 = NULL, *tree2 = NULL;
450 b74c7625 2018-05-20 stsp if (obj1 == NULL && obj2 == NULL)
451 b74c7625 2018-05-20 stsp return got_error(GOT_ERR_NO_OBJ);
453 cd0acaa7 2018-05-20 stsp if (obj1) {
454 cd0acaa7 2018-05-20 stsp err = got_object_tree_open(&tree1, repo, obj1);
458 cd0acaa7 2018-05-20 stsp if (obj2) {
459 cd0acaa7 2018-05-20 stsp err = got_object_tree_open(&tree2, repo, obj2);
463 11528a82 2018-05-19 stsp err = got_diff_tree(tree1, tree2, repo, outfile);
466 11528a82 2018-05-19 stsp got_object_tree_close(tree1);
468 11528a82 2018-05-19 stsp got_object_tree_close(tree2);
469 11528a82 2018-05-19 stsp return err;
472 4bb494d5 2018-06-16 stsp static char *
473 4bb494d5 2018-06-16 stsp get_datestr(time_t *time, char *datebuf)
475 4bb494d5 2018-06-16 stsp char *p, *s = ctime_r(time, datebuf);
476 4bb494d5 2018-06-16 stsp p = strchr(s, '\n');
482 11528a82 2018-05-19 stsp const struct got_error *
483 11528a82 2018-05-19 stsp got_diff_objects_as_commits(struct got_object *obj1, struct got_object *obj2,
484 11528a82 2018-05-19 stsp struct got_repository *repo, FILE *outfile)
486 11528a82 2018-05-19 stsp const struct got_error *err;
487 11528a82 2018-05-19 stsp struct got_commit_object *commit1 = NULL, *commit2 = NULL;
488 11528a82 2018-05-19 stsp struct got_object *tree_obj1 = NULL, *tree_obj2 = NULL;
489 9b697879 2018-05-20 stsp char *id_str;
490 4bb494d5 2018-06-16 stsp char datebuf[26];
491 4bb494d5 2018-06-16 stsp time_t time;
493 9b697879 2018-05-20 stsp if (obj2 == NULL)
494 b74c7625 2018-05-20 stsp return got_error(GOT_ERR_NO_OBJ);
496 cd0acaa7 2018-05-20 stsp if (obj1) {
497 cd0acaa7 2018-05-20 stsp err = got_object_commit_open(&commit1, repo, obj1);
500 cd0acaa7 2018-05-20 stsp err = got_object_open(&tree_obj1, repo, commit1->tree_id);
505 9b697879 2018-05-20 stsp err = got_object_commit_open(&commit2, repo, obj2);
508 9b697879 2018-05-20 stsp err = got_object_open(&tree_obj2, repo, commit2->tree_id);
511 9b697879 2018-05-20 stsp err = got_object_get_id_str(&id_str, obj2);
514 9fc8d6a2 2018-05-20 stsp if (fprintf(outfile, "commit: %s\n", id_str) < 0) {
515 9fc8d6a2 2018-05-20 stsp err = got_error_from_errno();
516 9fc8d6a2 2018-05-20 stsp free(id_str);
519 9b697879 2018-05-20 stsp free(id_str);
520 4bb494d5 2018-06-16 stsp time = mktime(&commit2->tm_author);
521 4bb494d5 2018-06-16 stsp if (fprintf(outfile, "author: %s %s UTC\n", commit2->author,
522 4bb494d5 2018-06-16 stsp get_datestr(&time, datebuf)) < 0) {
523 9fc8d6a2 2018-05-20 stsp err = got_error_from_errno();
526 4bb494d5 2018-06-16 stsp time = mktime(&commit2->tm_committer);
527 9fc8d6a2 2018-05-20 stsp if (strcmp(commit2->author, commit2->committer) != 0 &&
528 4bb494d5 2018-06-16 stsp fprintf(outfile, "committer: %s %s UTC\n", commit2->committer,
529 4bb494d5 2018-06-16 stsp get_datestr(&time, datebuf)) < 0) {
530 9fc8d6a2 2018-05-20 stsp err = got_error_from_errno();
533 9fc8d6a2 2018-05-20 stsp if (fprintf(outfile, "\n%s\n", commit2->logmsg) < 0) {
534 9fc8d6a2 2018-05-20 stsp err = got_error_from_errno();
538 11528a82 2018-05-19 stsp err = got_diff_objects_as_trees(tree_obj1, tree_obj2, repo, outfile);
540 11528a82 2018-05-19 stsp if (tree_obj1)
541 11528a82 2018-05-19 stsp got_object_close(tree_obj1);
542 11528a82 2018-05-19 stsp if (tree_obj2)
543 11528a82 2018-05-19 stsp got_object_close(tree_obj2);
544 11528a82 2018-05-19 stsp if (commit1)
545 11528a82 2018-05-19 stsp got_object_commit_close(commit1);
546 11528a82 2018-05-19 stsp if (commit2)
547 11528a82 2018-05-19 stsp got_object_commit_close(commit2);
548 11528a82 2018-05-19 stsp return err;